Good Afternoon,
Im new here so Hi All.

I having a problem doing a thing in c# asp, trying to get data, when updating the db trough the datagrid, using c# on the code behind and im havin troubles, can anybody help.

The code that im using is this:

  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();
        }

Recommended Answers

All 2 Replies

What error are you getting?

its this error "NUllReferenceException was unhandled by user code"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.