vb.net数据库连接 [英] vb.net db connection
本文介绍了vb.net数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
plz为我提供了将数据库连接到我的vb.net表单的代码。我在Sql server 2005中创建了我的数据库.plz help
解决方案
Dim strConnection As String = data source =(local); initial catalog = testDB; user id = sa; password = 1234;
Dim objConnection As 新 SqlConnection(strConnection)
Dim strSQL As 字符串 = SELECT * from tblTest;
Dim objCommand As 新 SqlCommand( strSQL,objConnection)
objConnection.Ope n()
Response.Write( ServerVersion:& objConnection.ServerVersion& _
vbCrLf& 数据源:& objConnection.DataSource& _
vbCrLf& 数据库:& objConnection.Database)
DataGrid1.DataSource = objCommand.ExecuteReader()
DataGrid1.DataBind()
objConnection.Close()
这是我在这里提到的一些演示程序代码,用于清除与vb.net的sql连接的概念..!
问候..!
Dnyanesh
你有什么尝试?我只能提供链接或代码片段来修复提出问题的人的代码,但我并不总是提供代码。即使我这样做了,我也不确定它是否有用,因为我不确定你会理解。我建议你开始阅读这个 [ ^ ]教程。它包含有关如何使用Winforms和VB.Net在数据库上添加,更新和删除记录的基本代码段。 MSDN [ ^ ]也有关于该主题的好文章。如果您需要更多资源,可以随时访问 Google [ ^ ]并对您可以获得的丰富信息感到惊讶。
您需要了解的有关ADO.NET的所有内容 where
要创建连接字符串,请检查here
plz provide me the code for connecting the database to my vb.net forms. i have created my database in Sql server 2005. plz help
解决方案
Dim strConnection As String = "data source=(local);initial catalog=testDB; user id=sa; password=1234;" Dim objConnection As New SqlConnection(strConnection) Dim strSQL As String = "SELECT * from tblTest;" Dim objCommand As New SqlCommand(strSQL, objConnection) objConnection.Open() Response.Write("ServerVersion: " & objConnection.ServerVersion & _ vbCrLf & "Datasource: " & objConnection.DataSource & _ vbCrLf & "Database: " & objConnection.Database) DataGrid1.DataSource = objCommand.ExecuteReader() DataGrid1.DataBind() objConnection.Close()
Here is some demo program code which i have mentioned here to clear the concept of sql connectivity with vb.net..!
Regards..!
Dnyanesh
What have you tried? I can only provide links, or code snippets to fix the code of the people asking the question, but I don't always provide code. And even if I did, I'm not sure if it helped because I'm not sure you will understand. I suggest you start reading this[^] tutorial. It includes basic code snippets on how to add, update, and delete records on your database using Winforms and VB.Net. MSDN[^] has also good articles regarding the topic. If you need more resources, you can always visit Google[^] and be amazed at the abundance of information that you can get.
all you need to know about ADO.NET is here
To create your connection string check here
这篇关于vb.net数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文