Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:01:15+00:00 2026-06-14T23:01:15+00:00

i have a little problem here: i have a combobox that gets its values

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:01:17+00:00Added an answer on June 14, 2026 at 11:01 pm

    It seems like you are trying to run a select command butt you are adding your parameters to the insert command.

            da2.SelectCommand.Parameters.Add("@DoctorCode", SqlDbType.Int).Value = Convert.ToInt32(comboBox2.SelectedValue);
            da2.SelectCommand.Parameters.Add("@month", SqlDbType.Int).Value = comboBox1.SelectedValue;
            da2.SelectCommand.Parameters.Add("@year", SqlDbType.Int).Value = textBox2.Text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm have little problem in retrieving the data from a table here's the code:
I use mongo, and I have a little problem here. I want to get
I have a little problem with export data to csv (comma-separated values). All data
I have a little problem with export data to csv (comma-separated values). All data
I have a little problem here. On my page I use a asp:repeater to
I have a little problem here with my user profile path for the use
I have a little problem with Jquery getJSON function. my json here { entries:
I have a little problem with javascript form submit issue, here is the script
I need a little push in the right direction. Here's my problem: I have
I have a litte problem here. I want to join twice from the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.