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(例外情况) { MessageBox.Show(ex.Message); } 当我调用此函数时所有文本框都填充数据但是当我在运行时从订单ID组合框中选择一个值时,没有任何更改值保持不变...解决方案是什么?i have 4 (Textbox ClientID, Name ,Address ,CellphoneNO) and one Combo Box Having OrderIDFirst the Query Run Using Clint ID that Return Some Data from Clienttable and some from Order TableClient may has Many Orders but there's only one details Shown when query run Beacase i don't have to use Datagridin the Order combobox id are Shown of different orderso 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,etcSqlConnection 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推荐答案你需要使用 HasRows 和而来浏览 DataReader 。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 } }} 这篇关于如何使用C#导航数据读取器中的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-06 03:17