急急急急急!!!!!!vb.net如何连接sql数据库,跪求详细步骤(完全新手) 50
因为是菜鸟,不熟悉visualstudio2005的使用方法所以暂时找不到哪里连接数据库。希望不是仅给代码而已,要越详细的连接数据库的步骤越好。最好要一步步解答下来,实在...
因为是菜鸟,不熟悉visual studio 2005的使用方法
所以暂时找不到哪里连接数据库。
希望不是仅给代码而已,要越详细的连接数据库的步骤越好。
最好要一步步解答下来,实在是不熟悉。
分数不是问题,高手速来啊!!!
在线等待中.... 展开
所以暂时找不到哪里连接数据库。
希望不是仅给代码而已,要越详细的连接数据库的步骤越好。
最好要一步步解答下来,实在是不熟悉。
分数不是问题,高手速来啊!!!
在线等待中.... 展开
1个回答
展开全部
Private privateConnection As SqlConnection
Private privateCommand As SqlCommand
Private privateSQLDataAdapter As SqlDataAdapter
Private privateDataSet As DataSet
private function getConnection(byval Server as string,byval Database as string,byval UserName as string,byval Password as string) as string
dim strConnectionString as string
strConnectionString = "Server=" + Server + ";Database=" + Database + ";User ID=" + UserName + ";Password=" + Password + ";"
return strConnectionString
end function
Public Function runSQLDataSet(ByVal SQL As String, Optional ByVal TableName As String = Nothing) As DataSet
Try
privateCommand = New SqlCommand(SQL, privateConnection)
privateDataSet = New DataSet
privateSQLDataAdapter = New SqlDataAdapter(privateCommand)
If TableName = Nothing Then
privateSQLDataAdapter.Fill(privateDataSet)
Else
privateSQLDataAdapter.Fill(privateDataSet, TableName)
End If
privateConnection.Close()
Return privateDataSet
Catch ExceptionObject As Exception
messagebox.show ExceptionObject.message
Finally
privateConnection.Close()
End Try
End Function
'以下为调用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
privateConnection = New SqlConnection(getConnection("Server","Database","UserName","Password"))
dim dstTmp as dataset
dstTmp=runSQLDataSet("select * from 表1","自定义dataset中表名")
End Sub
以上是简单的代码实现
不知道你有没有安装MSDN帮助文件,其实里面有很详细的说明
Private privateCommand As SqlCommand
Private privateSQLDataAdapter As SqlDataAdapter
Private privateDataSet As DataSet
private function getConnection(byval Server as string,byval Database as string,byval UserName as string,byval Password as string) as string
dim strConnectionString as string
strConnectionString = "Server=" + Server + ";Database=" + Database + ";User ID=" + UserName + ";Password=" + Password + ";"
return strConnectionString
end function
Public Function runSQLDataSet(ByVal SQL As String, Optional ByVal TableName As String = Nothing) As DataSet
Try
privateCommand = New SqlCommand(SQL, privateConnection)
privateDataSet = New DataSet
privateSQLDataAdapter = New SqlDataAdapter(privateCommand)
If TableName = Nothing Then
privateSQLDataAdapter.Fill(privateDataSet)
Else
privateSQLDataAdapter.Fill(privateDataSet, TableName)
End If
privateConnection.Close()
Return privateDataSet
Catch ExceptionObject As Exception
messagebox.show ExceptionObject.message
Finally
privateConnection.Close()
End Try
End Function
'以下为调用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
privateConnection = New SqlConnection(getConnection("Server","Database","UserName","Password"))
dim dstTmp as dataset
dstTmp=runSQLDataSet("select * from 表1","自定义dataset中表名")
End Sub
以上是简单的代码实现
不知道你有没有安装MSDN帮助文件,其实里面有很详细的说明
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询