重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
如果您要连接SQL Server 您可以参考以下代码。
创新互联是一家专注于网站建设、网站设计与策划设计,青田网站建设哪家好?创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:青田等地区。青田做网站价格咨询:028-86922220
您需要提供您的连接字符串“connectionString”
Public Shared Function Query(ByVal SQLString As String) As DataSet
Using connection As New SqlConnection(connectionString)
Dim ds As New DataSet()
Try
connection.Open()
Dim command As New SqlDataAdapter(SQLString, connection)
command.Fill(ds, "ds")
Catch ex As System.Data.SqlClient.SqlException
Throw New Exception(ex.Message)
End Try
Return ds
End Using
End Function
这是一个返回DataSet的函数。
调用非常简单。
如果您有什么不清楚的可以继续追问!希望能帮到您!
'读取方法:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ListBox1.Items.Clear()
Dim StrRed As StreamReader = New StreamReader("D:\111.txt", System.Text.Encoding.Default)
While Not StrRed.EndOfStream
Me.ListBox1.Items.Add(StrRed.ReadLine())
End While
StrRed.Dispose()
End Sub
End Class
'其它读写方法:
写入:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strR As New StreamWriter("D:\111.txt", True)'参数True表示 在原来的数据上面添加,如果为False这删除原来的数据 重新写入数据
strR.WriteLine(Me.TextBox2.Text)
strR.Dispose()
End Sub
读取:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strR As New StreamReader("D:\111.txt")
While Not strR.EndOfStream
Me.TextBox1.Text += strR.ReadLine() vbCrLf
End While
strR.Dispose()
End Sub
这里以OERACLE数据库为例 :
Provider=MSDAORA;data source =主机名:1521/ORCL;User ID=system;Password=ORACLE;Unicode=True
Dim myConn As Data.OleDb.OleDbConnection
myConn = New System.Data.OleDb.OleDbConnection()
myConn.ConnectionString = strCon
myConn.Open()
Option Explicit On
Option Strict On
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Program
Public Shared Sub Main()
Dim connectionString As String = _
"Data Source=(local);Initial Catalog=Northwind;" _
"Integrated Security=true"
' Provide the query string with a parameter placeholder.
Dim queryString As String = _
"SELECT ProductID, UnitPrice, ProductName from dbo.Products " _
"WHERE UnitPrice @pricePoint " _
"ORDER BY UnitPrice DESC;"
' Specify the parameter value.
Dim paramValue As Integer = 5
' Create and open the connection in a using block. This
' ensures that all resources will be closed and disposed
' when the code exits.
Using connection As New SqlConnection(connectionString)
' Create the Command and Parameter objects.
Dim command As New SqlCommand(queryString, connection)
command.Parameters.AddWithValue("@pricePoint", paramValue)
' Open the connection in a try/catch block.
' Create and execute the DataReader, writing the result
' set to the console window.
Try
connection.Open()
Dim dataReader As SqlDataReader = _
command.ExecuteReader()
Do While dataReader.Read()
Console.WriteLine( _
vbTab "{0}" vbTab "{1}" vbTab "{2}", _
dataReader(0), dataReader(1), dataReader(2))
Loop
dataReader.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadLine()
End Using
End Sub
End Class
这是我在vs2010中微软自带的MSDN示例代码里面拷的,是关于ADO.net连接sql的操作。
希望对你有帮助。 如果你还需要其他的,我也可以再拷给你看。