我是用C#.net寫出來的
創(chuàng)新互聯(lián)成都網(wǎng)站建設(shè)按需制作網(wǎng)站,是成都網(wǎng)站設(shè)計公司,為混凝土攪拌站提供網(wǎng)站建設(shè)服務(wù),有成熟的網(wǎng)站定制合作流程,提供網(wǎng)站定制設(shè)計服務(wù):原型圖制作、網(wǎng)站創(chuàng)意設(shè)計、前端HTML5制作、后臺程序開發(fā)等。成都網(wǎng)站營銷推廣熱線:028-86922220
SqlConnection myConn = new SqlConnection(sqlconnstring);
myConn.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT * from 表名", myConn);
thisAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable thisDataTable = new DataTable();
thisAdapter.Fill(thisDataTable);
DataTableReader thisReader = new DataTableReader(thisDataTable);
DataTable schemaTable = thisReader.GetSchemaTable();
foreach (DataRow dr in schemaTable.Rows)
{
MessageBox.Show(dr["ColumnName"].ToString());獲取字段名稱(f1 f2 f3)
MessageBox.Show(dr["ColumnSize"].ToString());獲取字段長度(2 2 2)
MessageBox.Show(dr["DataType"].ToString());獲取字段類(str str int)
}
下面是逐個顯示第一條記錄的各個字段值,通過實例,你應該可以操作想要的信息數(shù)據(jù)了:
'如果表里的記錄數(shù)大于0
If ds1.Tables("kucun").Rows.Count 0 Then
'依照數(shù)據(jù)表的字段值循環(huán)
For i = 0 To ds1.Tables("kucun").Columns.Count - 1
'顯示第一條記錄的第i個字段名和字段值
MsgBox(ds1.Tables("kucun").Columns(i).ColumnName ":" ds1.Tables("kucun").Rows(0)(i))
Next
End If
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示例代碼里面拷的,是關(guān)于ADO.net連接sql的操作。
希望對你有幫助。 如果你還需要其他的,我也可以再拷給你看。