hello,

I am working on a project in that i have perform the save,delete update option

now update is working. but when i search the data in my database the first entered data is not display. It save in the database properly but on the design form when i select the frst data its not working. I have close all the connection after my saving in completed. why this happen what should i do for that.

What does "when i select the frst data its not working" mean?
How do you select the first data?
What happens? or does not happen?
How do you know "It save in the database properly"?

the search coding is on combobox. when save butten is clicked then the data is save as id001 it display in combobox but when i tried to select from combobox it shows nothing not an erroor or data. after taht all data it shows(id002,id003,...id00n).

but only fist datais not displayed.


I hope now u understand my problem.

Please show some code.

I think you are doing .Read() an extra time so it skips the first Entry.

Please show some code so we can help you better.

Please post your code for the Combo box and save button so we can see better what you are doing.

For reading data from database i use the following code on combobox

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
    string val = comboBox3.Text.ToString();
            string contr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\hos.mdf;Integrated Security=True;User Instance=True";
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = contr;
            cn.Open();
            string str = "select nmed from purch  where nmed=@val ";

            SqlCommand cmd = new SqlCommand(str, cn);
            cmd.CommandType = CommandType.Text;
            SqlParameter sql;
            sql = cmd.Parameters.Add("@val", SqlDbType.VarChar, 15);
            sql.Value = val;
        }

and set the property of combobox

1. data sourse - binding data sourse.
2. display member
3. value menber.

In your code you don't add the parameter to the sql query.
Also you do not seem to be executing the sql query.

Do you update comboBox3.DataSource?
Are you using a BindingSource?
Please show the code where you set comboBox3.DataSource.

sql = cmd.Parameters.Add("@val", System.Data.SqlDbType.VarChar).Value = nmed
sql.Value = val;

;

try this...

like what nick told, I suppose u r missing the step where you execute the query..
or
are u using a data adapter or dataset...?

yes i have make the data set connection but in design window. in combox as i said in above thread i set the property

datasourse - outpatientBindingSourse
display member - opid because it has primary key constarint
value member - opid

What do you have set for
outpatientBindingSourse.DataSource = ?
outpatientBindingSourse.DataMember = ?

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.