how to connect sql database with vb.net form

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 65
Reputation: lich has a little shameless behaviour in the past 
Solved Threads: 4
lich lich is offline Offline
Junior Poster in Training

how to connect sql database with vb.net form

 
0
  #1
Feb 26th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 331
Reputation: freshfitz is an unknown quantity at this point 
Solved Threads: 27
freshfitz freshfitz is offline Offline
Posting Whiz

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

 
0
  #2
Feb 26th, 2009
Go into database explorer click connect to database
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

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

 
0
  #3
Feb 26th, 2009
In code you can do it this way
  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 13
Reputation: san_gwapo19 is an unknown quantity at this point 
Solved Threads: 0
san_gwapo19 san_gwapo19 is offline Offline
Newbie Poster

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

 
0
  #4
Feb 26th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 65
Reputation: lich has a little shameless behaviour in the past 
Solved Threads: 4
lich lich is offline Offline
Junior Poster in Training

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

 
0
  #5
Feb 26th, 2009
Thanks a lot

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

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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 65
Reputation: lich has a little shameless behaviour in the past 
Solved Threads: 4
lich lich is offline Offline
Junior Poster in Training

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

 
0
  #6
Feb 26th, 2009
Originally Posted by san_gwapo19 View Post
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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

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

 
0
  #7
Feb 26th, 2009
There are two sets of code in the above reply:
  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

  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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC