943,668 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 14503
  • VB.NET RSS
Feb 26th, 2009
0

how to connect sql database with vb.net form

Expand Post »
i want to connect the sql dabase to vb.net form. can anyone tel me how to do it. i tired google. but it only says about ms access database.

please help me
Similar Threads
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

Go into database explorer click connect to database
Reputation Points: 12
Solved Threads: 36
Posting Pro in Training
freshfitz is offline Offline
436 posts
since Sep 2008
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

In code you can do it this way
VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3. Public conn As SqlConnection
  4. conn = New SqlConnection("server = SRVERNAME ;database = DATABASENAME;Trusted_Connection = yes")

Then you can use conn.Open to open the connection and conn.close to close it.
Last edited by bajanpoet; Feb 26th, 2009 at 9:41 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

Imports System.Data.SqlClient
Dim con As New SqlClient.SqlConnection("data source=DATASOURCE;initial catalog=NAME OF DATABASE;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
con.Open()
con.Close()



THIS IS WHAT I USE TO CONNECT SQL TO VB.NET
this is a sample code below:

Imports System.Data.SqlClient

Public Class NEW_PERSONAL_INFORMATION

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim con As New SqlClient.SqlConnection("data source=ROOM310-40\SQLEXPRESS;initial catalog=DTIS;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
con.Open()
cmd.CommandText = "insert into perinfo values ('" & empid.Text & "','" & sname.Text & "','" & fname.Text & "','" & mname.Text & "','" & birthdate.Text & "','" & birthplace.Text & "','" & gender.Text & "','" & cstatus.Text & "','" & citizenship.Text & "','" & height.Text & "','" & weight.Text & "','" & btype.Text & "','" & address.Text & "','" & cp.Text & "','" & zcode.Text & "','" & telno.Text & "','" & email.Text & "','" & fathername.Text & "','" & mothername.Text & "'')"
cmd.ExecuteNonQuery()

MsgBox("Record is successfully stored")
con.Close()
End Sub
End Class

hope this can help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
san_gwapo19 is offline Offline
14 posts
since Jul 2008
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

Thanks a lot

i have did it.. but when i try to debug.. it gives me a error.. can anyone tell me y

Quote ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim con As New SqlClient.SqlConnection("data source=D:\Crap\Dialog Application Check Bill\Dialog Bill Check\Dialog Bill Check\database.mdf")
Dim cmd As New SqlCommand()
cmd.Connection = con
con.Open()
cmd.CommandText = "insert into DailySMS values ('" & txtInternational.Text & "','" & txtLocal.Text & "')"
cmd.ExecuteNonQuery()

MsgBox("Record is successfully stored")
con.Close()

End Sub
End Class
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

Imports System.Data.SqlClient
Dim con As New SqlClient.SqlConnection("data source=DATASOURCE;initial catalog=NAME OF DATABASE;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
con.Open()
con.Close()



THIS IS WHAT I USE TO CONNECT SQL TO VB.NET
this is a sample code below:

Imports System.Data.SqlClient

Public Class NEW_PERSONAL_INFORMATION

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim con As New SqlClient.SqlConnection("data source=ROOM310-40\SQLEXPRESS;initial catalog=DTIS;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
con.Open()
cmd.CommandText = "insert into perinfo values ('" & empid.Text & "','" & sname.Text & "','" & fname.Text & "','" & mname.Text & "','" & birthdate.Text & "','" & birthplace.Text & "','" & gender.Text & "','" & cstatus.Text & "','" & citizenship.Text & "','" & height.Text & "','" & weight.Text & "','" & btype.Text & "','" & address.Text & "','" & cp.Text & "','" & zcode.Text & "','" & telno.Text & "','" & email.Text & "','" & fathername.Text & "','" & mothername.Text & "'')"
cmd.ExecuteNonQuery()

MsgBox("Record is successfully stored")
con.Close()
End Sub
End Class

hope this can help

i have copied paste your code and edited it.. but it asking con is not declared..
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Feb 26th, 2009
0

Re: how to connect sql database with vb.net form

There are two sets of code in the above reply:
VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Data.SqlClient
  2. Dim con As New SqlClient.SqlConnection("data source=DATASOURCE;initial catalog=NAME OF DATABASE;Integrated Security=True")
  3. Dim cmd As New SqlCommand()
  4. cmd.Connection = con
  5. con.Open()
  6. con.Close()

and

VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Data.SqlClient
  2.  
  3. Public Class NEW_PERSONAL_INFORMATION
  4.  
  5. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  6. Dim con As New SqlClient.SqlConnection("data source=ROOM310-40\SQLEXPRESS;initial catalog=DTIS;Integrated Security=True")
  7. Dim cmd As New SqlCommand()
  8. cmd.Connection = con
  9. con.Open()
  10. cmd.CommandText = "insert into perinfo values ('" & empid.Text & "','" & sname.Text & "','" & fname.Text & "','" & mname.Text & "','" & birthdate.Text & "','" & birthplace.Text & "','" & gender.Text & "','" & cstatus.Text & "','" & citizenship.Text & "','" & height.Text & "','" & weight.Text & "','" & btype.Text & "','" & address.Text & "','" & cp.Text & "','" & zcode.Text & "','" & telno.Text & "','" & email.Text & "','" & fathername.Text & "','" & mothername.Text & "'')"
  11. cmd.ExecuteNonQuery()
  12.  
  13. MsgBox("Record is successfully stored")
  14. con.Close()
  15. End Sub
  16. End Class

Which one are you speaking of?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Sep 2nd, 2010
0

database

Click to Expand / Collapse  Quote originally posted by lich ...
i want to connect the sql dabase to vb.net form. can anyone tel me how to do it. i tired google. but it only says about ms access database.

please help me
hi i need help guys please give mo some codes to connect Vb to database..thank you.....im hoping for positive response...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aeonmj is offline Offline
1 posts
since Sep 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: error on ms access
Next Thread in VB.NET Forum Timeline: Hey can someone plz help me?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC