在VB中,怎么连接SQL数据库?使用的开发工具是Visual Studio 2010 ,连接字符串怎么写?
还有那个DataSet控件,不知道怎么用,数据库我直接在数据源那里连接好了,谢谢!这是报错提示...
还有那个DataSet 控件,不知道怎么用,数据库我直接在数据源那里连接好了,谢谢!
这是报错提示 展开
这是报错提示 展开
2个回答
2014-12-15
展开全部
Dim Conn As New SqlConnection("server= 服务器IP地址;database='数据库名';uid='数据库用户名';pwd='密码'")
示例一:
Dim conn As New OleDb.OleDbConnection
Dim cmmd As New OleDb.OleDbCommand
conn.ConnectionString = "provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=hindarerp;Persist Security Info=True;User ID=sa;Password=sa"
conn.Open()
cmmd.Connection = conn
cmmd.CommandText = "truncate table mytable"
cmmd.ExecuteScalar()
conn.Close()
示例二:
Dim conn As New OleDb.OleDbConnection
Dim cmmd As New OleDb.OleDbCommand
conn.ConnectionString = "provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=hindarerp;Persist Security Info=True;User ID=sa;Password=sa"
conn.Open()
cmmd.Connection = conn
cmmd.CommandText = "exec Hd_bom_add_data" '执行存储过程
cmmd.ExecuteScalar()
conn.Close()
示例一:
Dim conn As New OleDb.OleDbConnection
Dim cmmd As New OleDb.OleDbCommand
conn.ConnectionString = "provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=hindarerp;Persist Security Info=True;User ID=sa;Password=sa"
conn.Open()
cmmd.Connection = conn
cmmd.CommandText = "truncate table mytable"
cmmd.ExecuteScalar()
conn.Close()
示例二:
Dim conn As New OleDb.OleDbConnection
Dim cmmd As New OleDb.OleDbCommand
conn.ConnectionString = "provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=hindarerp;Persist Security Info=True;User ID=sa;Password=sa"
conn.Open()
cmmd.Connection = conn
cmmd.CommandText = "exec Hd_bom_add_data" '执行存储过程
cmmd.ExecuteScalar()
conn.Close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |