值:试图获取我想用下面的代码在一个GridView中取值上的GridView
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
string Username = row.Cells[3].Text;
string Password = row.Cells[4].Text;
string Email = row.Cells[5].Text;
string ID_Inscricao = row.Cells[1].Text;
SqlConnection sqlConn = new SqlConnection(
ConfigurationManager.ConnectionStrings["FormacaoConnectionString"].ToString());
SqlCommand sqlComm = new SqlCommand();
sqlComm = sqlConn.CreateCommand();
sqlComm.Parameters.Add("@Username", SqlDbType.Text);
sqlComm.Parameters.Add("@Password", SqlDbType.Text);
sqlComm.Parameters.Add("@Email", SqlDbType.Text);
sqlComm.Parameters.Add("@ID_Inscricao", SqlDbType.Text);
sqlComm.Parameters["@Username"].Value = Username;
sqlComm.Parameters["@Password"].Value = Password;
sqlComm.Parameters["@Email"].Value = Email;
sqlComm.Parameters["@ID_Inscricao"].Value = ID_Inscricao;
string sql = "INSERT INTO Utilizadores " +
"(Username, Password, Email,ID_Inscricao) " +
"VALUES (@Username, @Password, @Email, @ID_Inscricao)";
sqlComm.CommandText = sql;
sqlConn.Open();
sqlComm.ExecuteNonQuery();
sqlConn.Close();
}
所以,问题是我无法从GridView中获取值,而是得到一个“用户代码未处理NullReferenceException”。有人可以告诉我我做错了什么吗?
致以问候
你能告诉我们你在哪一行得到一个'NullReferenceException'。 – Jamiec 2012-08-09 14:30:11
Scratch,我想我看到它 - 您正在设置您尚未创建的参数的值(具体而言,您已在实际设置参数时注释了行) – Jamiec 2012-08-09 14:32:16