网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.net取数据库数据 vb获取数据库记录数

用VB.net连接数据库怎么获取其数据

如果您要连接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的函数。

调用非常简单。

如果您有什么不清楚的可以继续追问!希望能帮到您!

vb如何读取数据库一行数据?

'读取方法:

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

VB.NET怎么获取本机的数据库

这里以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()

求用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获取数据库记录数
新闻来源:http://bjjierui.cn/article/doegecd.html

其他资讯