Click here to Skip to main content
15,176,948 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
    SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   ='" + comboBox3.SelectedValue.ToString() + "'", objConn1);
    DataSet ds = new DataSet();
    da.Fill(ds, "dbo.GateEntry");
    if (ds.Tables["dbo.GateEntry"].Rows.Count > 0)
    {
        textBox3.Text = ds.Tables["GateEntry"].Rows[0]["Customer"].ToString();
        textBox1.Text = ds.Tables["GateEntry"].Rows[0]["Delivery"].ToString();
        comboBox1.SelectedItem = ds.Tables["GateEntry"].Rows[0]["Mode"].ToString();
        comboBox2.SelectedItem = ds.Tables["GateEntry"].Rows[0]["Inout"].ToString();
        textBox2.Text = ds.Tables["GateEntry"].Rows[0]["boxes"].ToString();
        dateTimePicker1.Value = Convert.ToDateTime(ds.Tables["GateEntry"].Rows[0]["Time"].ToString());
        textBox4.Text = ds.Tables["GateEntry"].Rows[0]["Person"].ToString();
        textBox5.Text = ds.Tables["GateEntry"].Rows[0]["Approved"].ToString();

    }
    else 
    {
    
    }
}
Posted
Updated 14-Sep-12 0:05am
v2
Comments
Adittya Gupta 14-Sep-12 9:22am
   
Do you have DataValueField and DataTextField same or different.

1 solution

Your code is correct but try this also.

C#
SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   ='" + comboBox3.SelectedValue.ToString().Trim() + "'", objConn1);


SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   LIKE'" + comboBox3.SelectedValue.ToString() + "%'", objConn1);


hope any of these help you..
   
Comments
[no name] 14-Sep-12 7:27am
   
So... you counsel people to write code that exposes themselves to SQL injection attacks?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900