public void readyDB(Object Sender, EventArgs e)
{
OleDbConnection Connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=E:\\Users\\pointedness\\source\\repos\\NetworkConfigure\\NetworkConfigure\\DB\\Network.accdb");
OleDbCommand Hold = Connection.CreateCommand();
Hold.CommandText = "select IP from IPAddress WHERE HostName='" + devicename.Text.ToString() + "'";
Connection.Open();
OleDbDataReader DBRx = Hold.ExecuteReader();
DataTable DBTx = new DataTable();
if (DBRx.HasRows)
{
for (int i = 0; i < DBRx.FieldCount; i++)
{
DBTx.Columns.Add(DBRx.GetName(i));
}
DBTx.Rows.Clear();
}
while (DBRx.Read())
{
DataRow row = DBTx.NewRow();
for (int i = 0; i < DBRx.FieldCount; i++)
{
row[i] = DBRx[i];
}
DBTx.Rows.Add(row);
}
Hold.Dispose();
Connection.Close();
string Consult = DBTx.ToString();
if (Consult == ipdircetory.Text.ToString())
{
Console.WriteLine(DBTx);
}
else
{
Console.WriteLine("zhibudui");
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.ok.MouseLeftButtonDown += new MouseButtonEventHandler(this.readyDB);
}
数据库只有一张表,两个值分别是hostname与ip(不区分大小写),数据库读取规则是通过text获得的devicename,在IPaddress表中获取到唯一的ip。
string consoult=dbtx.tostring(),是把获取的数据库返回值变成字符串,再在if里比较输出。
现在的状况是点击鼠标后什么反应都没有。0
各位大神,刚刚自学c#,实在是不懂,都找了很多网页看了都没有办法,谢谢各位不吝赐教。
目前运行时没有报错,vs2019 社区版。