VB.NET中有控件可以真接接点击属性进行连接配置.
永登网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联于2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
SqlConnect数据连接控件.点击ConnectionString属性进行配置就可以了.
VB.NET中没有RecordSet了.取而代之的是DataSet.
在VB.net中可以先用SqlConnection对像来连接数据库再用SqlDataAdapter对像来读取数据并填充到DataSet里.然后就可以进行数据绑定了.
例:
dim
conn
as
SqlConnection
dim
da
as
SqlDataAdapter
dim
ds
as
Dataset
set
conn
=
new
SqlConnection
conn.ConnectionString="server=serverIP;database=databasename;uid=userid;pwd=password";
conn.open
da
=
new
SqlDataAdapter
(,conn)
da.fill(ds)
Public sqlcon As System.Data.SqlClient.SqlConnection
Public sqladapter As System.Data.SqlClient.SqlDataAdapter
Public command As System.Data.SqlClient.SqlCommand
Public ds As System.Data.DataSet
Public dr As System.Data.DataTable
sqlcon = New System.Data.SqlClient.SqlConnection
sqlcon.ConnectionString = "Server=(local); Initial Catalog=test1 ; User ID="数据库sa用户"; Password="数据库密码""
ds = New System.Data.DataSet
dr = New System.Data.DataTable(" test2 ")
ds.Tables.Add(dr)
sqladapter = New System.Data.SqlClient.SqlDataAdapter("select * from test2 ", sqlcon)
sqlcon.Open()
sqladapter.Fill(dr)
sqlcon.Close()
界面上控件
DataGridView1.DataSource = dr
'引入
Imports System.Data
Imports System.Data.SqlClient
'数据库配置
Dim sql_conn As New SqlConnection("server=ip;database=tb1;user id=sa;password=ps")
' 过程
Dim add_m As New SqlCommand
add_m.Connection = sql_conn
add_m.CommandText = "insert into tb1(t1,t2) values(@t1,@t2)"
add_m.Parameters.AddWithValue("@t1",TEXTBOX1.text)
add_m.Parameters.AddWithValue("@t2",TEXTBOX2.text)
sql_conn.Open()
add_m.ExecuteNonQuery()
sql_conn.Close()
Const sql As String = "INSERT INTO idc (name, tel) VALUES (22,11)"
Const cnStr As String = "Data Source=(local);Initial Catalog=master;Integrated Security=False;User ID=sa;Password=123456;"
Dim cn As OleDbConnection = New OleDbConnection(cnStr)
Dim cmd As OleDbCommand = New OleDbCommand(sql)
cmd.ExecuteNonQuery()