任何人都可以通過ADO.Net爲我提供在VB2010 Express中添加數據庫連接的源代碼。包括所有添加,更新,刪除,檢索和修改數據庫字段的命令。如果任何人都可以爲我提供一個帶有源代碼的小型原型工作模型,那將會非常有幫助。通過VB2010中的ADO.Net實現數據庫連接express
0
A
回答
0
ADO.NET或多或少是基於SQL查詢的。因此,對於CRUD(創建,讀取,更新,刪除),操作查看SQL-Language(查詢語法可能會因您使用的數據庫而有所不同)。
的連接使用實現從System.Data
命名空間的IDbConnection
,IDbCommand
,IDbDataAdapter
,IDbDataParameter
和IDbTransaction
接口專業提供商實體。
存在不同的數據庫提供者(例如Microsoft SQL Server,Oracle,mySQl,OleDb,ODBC等)。其中一些本地支持的.NET框架(MSSQL = System.Data.SqlClient
命名空間,OleDb = System.Data.OleDb
,ODBC = System.Data.Odbc
命名空間),而其他人必須通過外部庫添加(如果你喜歡,你也可以編寫自己的數據庫提供者)。
使用IDBCommand對象(例如System.Data.SqlClient.SqlCommand
對象),您可以定義SQL命令。
這裏是一個小樣本片段可能幫助:
Public Class Form1
Sub DBTest()
'** Values to store the database values in
Dim col1 As String = "", col2 As String = ""
'** Open a connection (change the connectionstring to an appropriate value
'** for your database or load it from a config file)
Using conn As New SqlClient.SqlConnection("YourConnectionString")
'** Open the connection
conn.Open()
'** Create a Command object
Using cmd As SqlClient.SqlCommand = conn.CreateCommand()
'** Set the command text (=> SQL Query)
cmd.CommandText = "SELECT ID, Col1, Col2 FROM YourTable WHERE ID = @ID"
'** Add parameters
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = 100 '** Change to variable
'** Execute the value and get the reader object, since we are trying to
'** get a result from the query, for INSERT, UPDATE, DELETE use
'** "ExecuteNonQuery" method which returns an Integer
Using reader As SqlClient.SqlDataReader = cmd.ExecuteReader()
'** Check if the result has returned som results and read the first record
'** If you have multiple records execute the Read() method until it returns false
If reader.HasRows AndAlso reader.Read() Then
'** Read the values of the current columns
col1 = reader("col1")
col2 = reader("col2")
End If
End Using
End Using
Debug.Print("Col1={0},Col2={1}", col1, col2)
'** Close the connection
conn.Close()
End Using
End Sub
End Class
相關問題
- 1. 通過ADO.NET連接數據庫存儲過程
- 2. 連接到數據庫(ADO.NET,SQL Server)的
- 3. 通過HTTP處理程序連接到SQL Server Express數據庫
- 4. 使用C#express通過ODBC連接到MySQL數據庫
- 5. 連接到vb2010中的嵌入式Access數據庫
- 6. 如何使用ADO.Net連接數據庫?
- 7. 使用ODBC連接到ADO.NET數據庫
- 8. Ruby/Rails數據庫連接池實現
- 9. 通過ADO.NET記錄數據庫訪問
- 10. 通過ADO.Net同步SQL數據庫
- 11. 通過類的數據庫連接
- 12. 通過代理的數據庫連接
- 13. 使用oracle數據庫通過jdbc實現連接池時出現錯誤
- 14. 當我使用ADO.NET連接到數據庫時,出現錯誤
- 15. 通過PHP的MySQL數據庫連接的單個實例類
- 16. 通過SSH連接到MySQL數據庫
- 17. 通過NetBeans連接到Oracle數據庫
- 18. 通過.pem連接到數據庫
- 19. iPhone:通過Internet連接到數據庫?
- 20. 通過SQLPLUS連接Oracle數據庫
- 21. 通過局域網連接數據庫
- 22. 通過config.properties連接數據庫
- 23. 通過python連接到MySQL數據庫
- 24. 通過PHP連接到Oracle數據庫
- 25. 通過數據庫連接。 php
- 26. 通過mongojs連接到monogolab數據庫
- 27. 通過PHP連接到Sharepoint數據庫
- 28. 通過PHP連接到SOQL數據庫
- 29. 通過php連接數據庫
- 30. OOP - 通過__construct連接到數據庫
檢查這本書: http://evry1falls.freevar.com/VBNet/index.html – 2012-08-19 22:19:31