Click here to Skip to main content
16,020,840 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
i have 4 (Textbox ClientID, Name ,Address ,CellphoneNO) and one Combo Box Having OrderID
First the Query Run Using Clint ID that Return Some Data from Clienttable and some from Order Table
Client may has Many Orders but there's only one details Shown when query run Beacase i don't have to use Datagrid
in the Order combobox id are Shown of different order
so i want to select id from Order combo box to further search the datareader for remaing orders that are not shown and the result of a form sudden change and show records in the textboxes of Name ,address,etc

SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
string proce = procstr;
SqlCommand cmd = new SqlCommand(proce,conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter(dbpar,dbtype)).Value=searchkey;

SqlDataAdapter da = new SqlDataAdapter(cmd);

SqlDataReader reader = reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.HasRows)
{
int rowcount = 0;
while (reader.Read())
{
rowcount++;
txtid.Text = reader["ClientID"].ToString();
txtname.Text = reader["Name"].ToString();
txtmobile.Text = reader["Mobile"].ToString();
txtcity.Text = reader["city"].ToString();
txtaddress.Text = reader["address"].ToString();
cmborderid.Items.Add(reader["orderId"].ToString());
tsddate.Text = reader["DDate"].ToString();
lbddayleft.Text = reader["Days_Left"].ToString();
ttstatus.Text = reader["Status"].ToString();conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

}

when i call this function All the Textboxs are Fill with data but when i select a value from order id combobox at run time nothing change value remain the same ...what's the solution
Posted
Updated 3-Feb-14 8:18am
v2

1 solution

You need to use HasRows and while to navigate through a DataReader.

using (SqlDataReader dr = cmd.ExecuteReader())
{
    if (dr.HasRows)
    {
        while (dr.Read())
        {
            ....do stuff here
        }
    }
}
 
Share this answer
 
Comments
abdul manan 7 3-Feb-14 14:06pm    
thanks i have done
all Textboxes are Filled with Data
now problm is that when i select a value from order id combobox
the values doesnot change
still the same
Florian Trück 3-Feb-14 18:15pm    
Do you fill the combo boxes in page load?
If yes, you have to check the selected value first and then mark the value as selected when filling the combo boxes again.

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