如何将excel单元格TEXT显示为组合框 [英] how to display an excel cell TEXT into a combobox
本文介绍了如何将excel单元格TEXT显示为组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码
private void btnshow_Click( object sender,EventArgs e)
{
string connStr = provider = Microsoft.Jet.OLEDB.4.0; Data Source ='c:\\KBE \\\ \\ solidolid1.xls';扩展属性= Excel 8.0;;
OleDbConnection MyConnection;
DataSet ds1;
OleDbDataAdapter MyCommand1;
MyConnection = new OleDbConnection(connStr);
MyCommand1 = new OleDbDataAdapter( select *来自[INPUT $],MyConnection);
ds1 = new System.Data.DataSet();
MyCommand1.Fill(ds1);
DataTable dt1 = new DataTable();
dt1 = ds1.Tables [ 0 ];
cbf.Items.Insert( 0 ,dt1.Rows [ 1 ] [ Value]。ToString());
textBox1.Text = dt1.Rows [ 2 ] [ 值跨度>]的ToString();
textBox2.Text = dt1.Rows [ 3 ] [ 值跨度>]的ToString();
comboBox2.Text = dt1.Rows [ 6 ] [ Value]。来自此代码的ToString();
我只获得了文本框值但没有获得comboBox文本
所以请告诉我建议这个程序需要什么更改
谢谢
解决方案
,MyConnection);
ds1 = new System.Data.DataSet() ;
MyCommand1.Fill(ds1);
DataTable dt1 = new DataTable();
dt1 = ds1.Tables [ 0 ];
cbf.Items.Insert( 0 ,dt1.Rows [< span class =code-digit> 1 ] [ Value]。ToString ());
textBox1.Text = dt1.Rows [ 2 ] [ Value跨度>]的ToString();
textBox2.Text = dt1.Rows [ 3 ] [ 值跨度>]的ToString();
comboBox2.Text = dt1.Rows [ 6 ] [ Value]。来自此代码的ToString();
我只获得了文本框值但没有获得comboBox文本
所以请告诉我建议这个程序需要进行哪些更改
谢谢
ComboBox [ ^ ]类有几个属性 [ ^ ],例如:
DataSource [ ^ ]
DisplayMember [ ^ ]
ValueMember [ ^ ]
您可以使用它们来绑定数据;)
comboBox2.DataSource = dt1
comboBox2.DisplayMember = Fie LD1\" 跨度>;
comboBox2.ValueMember = Field2;
i use this code
private void btnshow_Click(object sender, EventArgs e)
{
string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\KBE\\solid piston1.xls';Extended Properties=Excel 8.0;";
OleDbConnection MyConnection;
DataSet ds1;
OleDbDataAdapter MyCommand1;
MyConnection = new OleDbConnection(connStr);
MyCommand1 = new OleDbDataAdapter("select * from [INPUT$]", MyConnection);
ds1 = new System.Data.DataSet();
MyCommand1.Fill(ds1);
DataTable dt1 = new DataTable();
dt1 = ds1.Tables[0];
cbf.Items.Insert(0, dt1.Rows[1]["Value"].ToString());
textBox1.Text = dt1.Rows[2]["Value"].ToString();
textBox2.Text = dt1.Rows[3]["Value"].ToString();
comboBox2.Text = dt1.Rows[6]["Value"].ToString();
from this code i got only textbox value but not got comboBox text
so please tell me suggestion what change required in this programme
thanks
解决方案
", MyConnection); ds1 = new System.Data.DataSet(); MyCommand1.Fill(ds1); DataTable dt1 = new DataTable(); dt1 = ds1.Tables[0]; cbf.Items.Insert(0, dt1.Rows[1]["Value"].ToString()); textBox1.Text = dt1.Rows[2]["Value"].ToString(); textBox2.Text = dt1.Rows[3]["Value"].ToString(); comboBox2.Text = dt1.Rows[6]["Value"].ToString();
from this code i got only textbox value but not got comboBox text
so please tell me suggestion what change required in this programme
thanks
ComboBox[^] class has got several properties[^], for example:
DataSource[^]
DisplayMember[^]
ValueMember[^]
You can use them to bind data ;)
comboBox2.DataSource=dt1 comboBox2.DisplayMember = "Field1"; comboBox2.ValueMember = "Field2";
这篇关于如何将excel单元格TEXT显示为组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文