Shivaraj Poojary

Shivaraj Poojary

  • NA
  • 92
  • 314.9k

Update

Nov 26 2010 2:35 AM
Hiiii....i have the following code for updating database but am gettin error like "Object reference not set to an instance of an object" please help me..

 private void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            string strConnection = "Integrated Security=SSPI;Persist Security Info=False;User ID=CRYSYS1-DESKTOP\\SQLEXPRESS\\Student;Initial Catalog=ipRFID;Data Source=CRYSYS1-DESKTOP\\SQLEXPRESS";
            con = new SqlConnection(strConnection);
            con.Open();
            string command = "UPDATE TB_EmployeeMaster set Version=@Version,Operating System=@OS,Processor=@Processor,RAM=@RAM where RecId='" + txtID.Text + "'";

            cmd = new SqlCommand(command,da.SelectCommand.Connection);
            cmd.Parameters.AddWithValue("@RecId", txtID.Text);
            cmd.Parameters.AddWithValue("@Version", txtVersion.Text);
            cmd.Parameters.AddWithValue("@OS", txtOS.Text);
            cmd.Parameters.AddWithValue("@Processor", txtProcessor.Text);
            cmd.Parameters.AddWithValue("@RAM", txtRAM.Text);
            DataSet ds = new DataSet();
            da.UpdateCommand = cmd;

            da.Fill(ds, "TB_EmployeeMaster");
            da.Update(ds, "TB_EmployeeMaster");
            //cmd.ExecuteNonQuery();
            MessageBox.Show("Updated");

            con.Close();
}

Answers (2)