可以利用窗体对数据库的 *** 作有哪些

可以利用窗体对数据库的 *** 作有哪些,第1张

看你的mysql当前默认的存储引擎:

mysql>show variables like '%storage_engine%'

你要看某个表用了什么引擎(在显示结果里参数engine后面的就表示该表当前用的存储引擎):

mysql>show create table 表名

1.实现对数据库连接

publicstatic SqlConnection conn

staticvoid Main(string[] args)

{

ConnectionDb()

UpdateCommand()

Console.WriteLine(SelectCommand())

}

///<summary>

/// 数据库连接

///</summary>

privatestaticvoid ConnectionDb()

{

/* 介绍数据库连接的一些参数

* UID:连接数据库的用户名

* Password:连接数据库密码

* Initial Catalog:连接数据库的名称

* Data Source:数据库建的IP地址

*/

conn =new SqlConnection("UID=***Password=***Initial Catalog=SmokeTestData Source=192.168.*.*")

conn.Open()

}

2.对数据进行查询访问

///<summary>

/// 数据库查询

///</summary>

///<returns>返回查询结果</returns>

privatestaticstring SelectCommand()

{

var strCmd ="SELECT [Ip],[IsWatch] FROM [SmokeTest].[dbo].[Machine]"+

"Where [IP]=\'192.168.*.*\'"

try

{

SqlCommand sqlComm =new SqlCommand()

sqlComm.Connection = conn

sqlComm.CommandText = strCmd

var abc = sqlComm.ExecuteNonQuery()

if (abc !=-1)

{

return""

}

SqlDataReader dataReader = sqlComm.ExecuteReader()

while (dataReader.Read())

{

return"机器IP:"+ dataReader["IP"] +"\t"+"监控状态:"+ dataReader["IsWatch"]

}

return"老大,没找到对应的IP喔!"

}

catch (Exception ex)

{

Console.WriteLine(ex.Message)

return"相当杯具啊,获取机器状态出异常了。"+ ex.Message

}

}

privatestaticbool UpdateCommand()

{

string strCmd ="update [SmokeTest].[dbo].[Machine]"+

"set [IsWatch] = \'1\'"+

"where IP = \'192.168.*.*\'"

try

{

SqlCommand sqlComm =new SqlCommand()

sqlComm.Connection = conn

sqlComm.CommandText = strCmd

sqlComm.ExecuteNonQuery()

returntrue

}

catch (Exception ex)

{

Console.WriteLine(ex.Message)

returnfalse

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9784331.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存