任何人都可以通过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