在vs中怎么实现modbus数据采集以及存入sql server

在vs中怎么实现modbus数据采集以及存入sql server,第1张

在vs中怎么实现modbus数据采集以及存入sql server

//1声明数据库连接字符串 string strcon = "data source=;initial catalog=itdb;uid=sa;pwd=sun@0918"; //2创建数据库连接对象 SqlConnection con = new SqlConnection(strcon); //3打开数据库连接 conOpen(); /

1、首先把连接数据库字符串配置到webconfig文件,如:

<connectionStrings>

<add name="ConnectionString" connectionString="Data Source=127001;Initial

Catalog=xueitdb;Integrated Security=False;User=sa;Pwd=test;" providerName="SqlServer"/>

</connectionStrings>

2、创建一个文件indexaspx,后台cs首先引用

using SystemConfiguration;

using SystemDataSqlClient;

下面示范代码:

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

try

{

//读取webconfig配置文件数据库连接字符串

string strConstring = ConfigurationManagerConnectionStrings

["ConnectionString"]ConnectionString;

//创建sql数据库连接对象

SqlConnection conn = new SqlConnection();

connConnectionString = strConstring;

connOpen();

ResponseWrite("连接学it网的sql 2005数据库成功");

}

catch (Exception ex)

{

ResponseWrite("连接数据库失败" exMessage);

}

}

}

接下来就是实现登录

protected void Button1_Click1(object sender, EventArgs e)

{

Conn con = new Conn();

string strSql = "select from DLB where XH='" + thisTextnameTextTrim() + "' and KL='" + thisTextpwgText + "'";

SqlDataReader read = conExceRead(strSql );

readRead();

if (readHasRows)

{

Session["XH"] = thisTextnameTextTrim();

PageResponseRedirect("~/aspx");

}

else

{

ResponseWrite(ccObjMessageBoxPage("用户名或密码有误!"));

ResponseRedirect("~/indexaspx");

}

}

//1声明数据库连接字符串stringstrcon="datasource=;initialcatalog=itdb;uid=sa;pwd=sun@0918";//2创建数据库连接对象SqlConnectioncon=newSqlConnection(strcon);//3打开数据库连接conOpen();//4编写SQL语句stringsql="deletefromphzwwherename='"+id+"'";SqlCommandcmd=newSqlCommand(sql,con);//6选择Command的适合方法intres=cmdExecuteNonQuery();if(res>0){MessageBoxShow("删除成功");thisBindData();}else{MessageBoxShow("删除失败");}//7关闭数据库连接conClose();这是删除的初级代码,新增和修改,只需修改SQL语句就可以了

以上就是关于在vs中怎么实现modbus数据采集以及存入sql server全部的内容,包括:在vs中怎么实现modbus数据采集以及存入sql server、ASP.net 数据库连接不太会 求高手指教!谢谢、报表中可以对输入的内容进行增加,删除,修改是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/sjk/10110331.html

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

发表评论

登录后才能评论

评论列表(0条)

保存