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