Click here to Skip to main content
14,696,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 1-Apr-20 16:59pm
Comments
Member 8327439 15-Mar-12 2:49am
   
Just a note,
If you are connecting to a free online sql server you may not have the permissions to do that, however you should be able to connect to a Localhost sql server for testing and all that.
It took me a bit to get a vb.net to sql connection string in some of my first projects I was working on.

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
   
v2
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
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900