求VB.net连接SqlServer 数据库
rt 各种操作 --------------------编程问答----------------------------------------编程问答-------------------- 追加,删除等操作只要在SqlCommand中提供对应的SQl就可 --------------------编程问答-------------------- 推荐楼主百度下“PDF.NET数据开发框架”,以后不用为操作数据库分心了。 --------------------编程问答-------------------- 也提供一种
Public Class DataGridSend_
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlDa As SqlDataAdapter
Dim sqlDs As DataSet
Dim sqlDv As DataView
Dim sqlDt As DataTable
Private Sub DataGridSend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlConn = New SqlConnection("Data Source=.;Initial Catalog=jwinfo;Integrated Security=True;")
sqlDa = New SqlDataAdapter("SELECT * FROM 学生信息", sqlConn)
sqlDs = New DataSet()
sqlDa.Fill(sqlDs, "学生信息")
DataGridView1.DataSource = sqlDs.Tables("学生信息")
End Sub
--------------------编程问答-------------------- 学会一种就行了,记住一种数据库连接字符串的格式就OK啦,何必搞得这么复杂 --------------------编程问答-------------------- 上面说的都对啊 --------------------编程问答--------------------
Dim MyCon As New ADODB.Connection
Dim MyRec As New ADODB.Recordset
Dim mCnnDB As String
Dim strSql As String
mCnnDB = "Driver={sql server};server=" & ServerName & ";uid=" & UserId & ";pwd=" & UserPwd & ";database=" & DBName
MyCon.ConnectionString = mCnnDB
MyCon.ConnectionTimeout = 60
MyCon.Open()
MyRec.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
MyRec.LockType = ADODB.LockTypeEnum.adLockPessimistic
strSql = "update TableName set RegSpotRate = " & dblSpot & _
" where PairCode = '" & strPairCode & "' and RSR_EntityID = 5"
MyRec.Open(strSql, MyCon)
MyCon.Close()
Public Sub GetConn()--------------------编程问答-------------------- conn.int 中的内容如下Data Source=localhost;Initial Catalog=Lesson;Integrated Security=True --------------------编程问答-------------------- 百度一下,你都知道 --------------------编程问答-------------------- 路过... --------------------编程问答-------------------- Dim a As New SqlClient.SqlConnection
'从配置文件得到连接字符串
Dim strFileName As String = "conn.ini"
Dim objReader As StreamReader = New StreamReader(strFileName)
strConn = objReader.ReadToEnd()
'MsgBox(strConn)
objReader.Close()
objReader = Nothing
End Sub
a.ConnectionString = "Data Source=要链接的服务器名;InitialCatalog=要链的数据库名;Integrated Security=true"
a.Open()
--------------------编程问答--------------------
补充:.NET技术 , VB.NET