vb.net读取数据库 vb读取数据库数据

求用vb.net写一个读取数据库数据的简单操作 。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的操作 。
【vb.net读取数据库 vb读取数据库数据】希望对你有帮助 。如果你还需要其他的,我也可以再拷给你看 。
vb.NET 关于数据库的读写 - 高分Dim da As New OleDb.OleDbDataAdapter(‘’输入2/3/4其中的答案)
Dim ds As New DataSet
da.Fill(ds, "Table1")
Dim dt As DataTable
dt = ds.Tables("Table1")
//2. Cmd.CommandText = "select 序号 from 账号 where 姓名='小李'"
//3. Cmd.CommandText = "select 序号 from 账号 where 姓名='小张'"
//4. Cmd.CommandText = "insert into 账号(姓名,年龄,性别,序号) values('张三','22','男','4')"
DataGridView1.DataSource = dt'建立datagridview来显示资料
myCn.Close()
vb.net读取数据库时假死不显示进度条你问的是vb.net读取数据库时假死不显示进度条怎么办吧,在循环代码中加一句DoEvents语句 。
根据微软公司的资料得知,这是一种bug , 只要在循环代码中加一句DoEvents语句即可 。
VB.Net是一种简单 , 现代 , 面向对象的计算机编程语言,由微软开发 。
VB.NET怎么获取本机的数据库这里以OERACLE数据库为例 vb.net读取数据库:
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()
vb.net 怎么操作数据库如果楼主熟悉VB6,可以直接在项目中添加ADODB的Com引用,这样你就可以像VB6那样操作数据库了!
另外
.NET
Framework中连接数据库要用到ADO.NET 。如果要操作Access数据库 , 要用到System.Data.OleDb命名空间下的许多类 。
比如按楼主所说,“我想在textbox1中显示表一中【一些数据】字段下的第一个内容”:
'首先导入命名空间
Imports
System.Data
Imports
System.Data.OleDb
'然后在某一个事件处理程序中写:
Dim
conn
As
New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data

推荐阅读