i have a little problem here: i have a combobox that gets its values from column in database and i use it to enter data back to another palce in database like
comboBox2.DataSource = ds1.Tables[0];
comboBox2.DisplayMember = "DoctorName";
comboBox2.ValueMember = "DoctorCode";
comboBox2.BindingContext = this.BindingContext;
this fill the combobox with the name of doctors and the value will be the code of doctor then
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\users\administrator\documents\visual studio 2010\Projects\Clinic\Clinic\Clinc.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();
SqlCommand cmd1 = new SqlCommand("SELECT Doctors.DoctorCode, Doctors.DoctorName, SessionReservations.SessionCode, SessionReservations.PatientCode, SessionReservations.ExaminationCode, SessionReservations.DoctorCode AS Expr1, SessionReservations.SessionMonth, SessionReservations.SessionYear FROM Doctors INNER JOIN SessionReservations ON Doctors.DoctorCode = SessionReservations.DoctorCode WHERE (Doctors.DoctorCode = @DoctorCode) AND (SessionReservations.SessionMonth = @month) AND (SessionReservations.SessionYear = @year)", con);
SqlDataAdapter da2 = new SqlDataAdapter(cmd1);
DataSet ds2 = new DataSet();
try
{
da2.InsertCommand.Parameters.Add("@DoctorCode", SqlDbType.Int).Value = Convert.ToInt32(comboBox2.SelectedValue);
da2.InsertCommand.Parameters.Add("@month", SqlDbType.Int).Value = comboBox1.SelectedValue;
da2.InsertCommand.Parameters.Add("@year", SqlDbType.Int).Value = textBox2.Text;
da2.Fill(ds2);
cmd1.ExecuteReader();
con.Close();
}
this code is for selecting specific rows and the select statment is working right in sql manager but while running it gives error that
"System.NullReferenceException: Object reference not set to an instance of an object. at Clinic.DoctorMoneyCall.button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\documents\visual studio 2010\Projects\Clinic\Clinic\DoctorMoneyCall.cs:line 45"
i just don't understand what's going wrong