本文介绍了如何使用数据集功能填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 实际上,我在存储过程的帮助下在数据访问层上编写了一个函数,并希望在comboBox1_SelectedIndexChanged上调用此函数,我希望用dilldataset()填充我的文本框。 public DataSet Filldataset(Bussinessobject.BOEBO) { objconn = newSqlConnection(的ConnectionString); objconn.Open(); objcommand = newSqlCommand( sp_filltextfromcombo,objconn); objcommand.CommandType = CommandType.StoredProcedure; objcommand.Parameters.AddWithValue( @ name,EBO.fname ); SqlDataAdapterda = newSqlDataAdapter(); da.SelectCommand = objcommand; // DataTable dt = new DataTable(tblEmployeeInfo); DataSetobjdataset = newDataSet(); da.Fill(objdataset); return objdataset; } im在这里调用Filldataset函数来填充这个文本框但是我不能帮助我在帮助我在文本框中获取数据帮助这个filldataset()PLZ让我纠正如果我错了我需要一些代码PLZ private void comboBox1_SelectedIndexChanged(objectsender,EventArgse) { Bussinessobject.BOEBO = newBussinessobject.BO(); comboBox1.DataSource = EBO.Filldataset(EBO)。表[ 0 ]; txtEid.Text = Convert.ToInt32(EBO.Filldataset(EBO).Tables [ 0 ]。行[ 0 ] [ 0 ])。ToString(); txtEfname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables [ 0 ]。行[ 0 ] [ 1 ]); txtElname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables [ 0 ]。行[ 0 ] [ 2 ]); } 解决方案 嘿那里, 将SelectedIndexChanged事件更改为: private void comboBox1_SelectedIndexChanged( object sender,EventArgs e) { Bussinessobject.BOEBO = newBussinessobject.BO(); DataSet ds = EBO.Filldataset(EBO); if (ds!= null && ds.Tables。计数> 0 ) { DataTable dt = EBO.Filldataset(EBO) )。表[ 0 ]; if (dt!= null && dt.Rows.Count > 0 ) { txtEid.Text = dt.Rows [ 0 ] [ 0 ]。ToString(); txtEfname.Text = dt.Rows [ 0 ] [ 1 ]。ToString(); txtElname.Text = dt.Rows [ 0 ] [ 2 ]。ToString(); } } } 如果你知道具体的列名你可以指定它们这个: dt.Rows [ 0 ] [ YourColumnName]。ToString() 让我知道是否有帮助。 Azee ...... Hi, actually, i wrote a function on Data Access layer with the help of stored procedurę and want to call this function on comboBox1_SelectedIndexChanged and i want ot fill my textboxes with dilldataset().public DataSet Filldataset(Bussinessobject.BOEBO) { objconn = newSqlConnection(connectionstring); objconn.Open(); objcommand = newSqlCommand("sp_filltextfromcombo", objconn); objcommand.CommandType = CommandType.StoredProcedure; objcommand.Parameters.AddWithValue("@name",EBO.fname); SqlDataAdapterda = newSqlDataAdapter(); da.SelectCommand = objcommand; // DataTable dt = new DataTable("tblEmployeeInfo"); DataSetobjdataset = newDataSet(); da.Fill(objdataset); return objdataset; }i m calling Filldataset function here for fill this textboxes but i can't plz some one help me to fetch data in textboxes with the help of this filldataset()plz make me correct if i m wrong i need some code plz private void comboBox1_SelectedIndexChanged(objectsender, EventArgse) { Bussinessobject.BOEBO = newBussinessobject.BO(); comboBox1.DataSource = EBO.Filldataset(EBO).Tables[0]; txtEid.Text = Convert.ToInt32(EBO.Filldataset(EBO).Tables[0].Rows[0][0]).ToString(); txtEfname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables[0].Rows[0][1]); txtElname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables[0].Rows[0][2]); } 解决方案 Hey there,Change the SelectedIndexChanged event to this:private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Bussinessobject.BOEBO = newBussinessobject.BO(); DataSet ds = EBO.Filldataset(EBO); if (ds != null && ds.Tables.Count > 0) { DataTable dt = EBO.Filldataset(EBO).Tables[0]; if (dt != null && dt.Rows.Count > 0) { txtEid.Text = dt.Rows[0][0].ToString(); txtEfname.Text = dt.Rows[0][1].ToString(); txtElname.Text = dt.Rows[0][2].ToString(); } } }if you know the specific Column names you can specify them like this:dt.Rows[0]["YourColumnName"].ToString()Let me know if helps.Azee... 这篇关于如何使用数据集功能填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-20 17:33