1
我需要通过为每个数据网格引用两个单独的文本文件来将数据添加到数据网格中的两个单独列。这两列称为MACAddress和TxPower。产生的数据网格应该在相关的MAC地址前面提供TxPower。但目前我在单独的行中接收MACAddress和TxPower。将数据插入数据网格中的行中的问题
我知道如何通过引用单个文本文件来获取相应MAC地址的Txpower。但是,这里我遇到的困难是使用两个单独的文本文件来获取表格。请帮忙。在此先感谢
,我使用的编码下面给出:
DataTable dtt = new DataTable();
dtt.Columns.Add("MACAddress", typeof(string));
dtt.Columns.Add("TxPower", typeof(string));
try
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(textBox1.Text.Replace("'\'", "'\\'")))
{
string line, mac;
while ((line = sr.ReadLine()) != null)
{
DataRow DTR = dtt.NewRow();
DTR["MACAddress"] = mac;
dtt.Rows.Add(DTR);
dataGridView1.DataSource = dtt;
}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
try
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(textBox2.Text.Replace("'\'", "'\\'")))
{
string line;
while ((line = sr.ReadLine()) != null)
{
DataRow DTR=dtt.NewRow();
DTR["TxPower"] = line.Substring(78, 4);
dtt.Rows.Add(DTR);
dataGridView1.DataSource = dtt;
}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
是的。这正是我想要的。谢谢 – 2012-02-09 11:57:27