| | |
how to connect sql database with vb.net form
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 88
Reputation:
Solved Threads: 0
In code you can do it this way
Then you can use
VB.NET Syntax (Toggle Plain Text)
Imports System.Data Imports System.Data.SqlClient Public conn As SqlConnection 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.
•
•
Join Date: Jul 2008
Posts: 13
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2008
Posts: 65
Reputation:
Solved Threads: 4
Thanks a lot
i have did it.. but when i try to debug.. it gives me a error.. can anyone tell me y
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
•
•
Join Date: May 2008
Posts: 65
Reputation:
Solved Threads: 4
•
•
•
•
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..
•
•
Join Date: Sep 2006
Posts: 88
Reputation:
Solved Threads: 0
There are two sets of code in the above reply:
and
Which one are you speaking of?
VB.NET Syntax (Toggle Plain Text)
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()
and
VB.NET Syntax (Toggle Plain Text)
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
Which one are you speaking of?
![]() |
Similar Threads
- how to attach sqldatabase with sql server dbms from a form of vb.net (VB.NET)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- A Complete Database Project (VB.NET)
- how to update an access DB with vb.net? (ASP.NET)
- Accessing Oracle stored functions from asp.net (ASP.NET)
- Visual Basic.net Database application (VB.NET)
- How to connect a SQL stored procedure to a windows application? (VB.NET)
- HOWTO: Share an SQL Connection between multiple forms within the same project (C#)
Other Threads in the VB.NET Forum
- Previous Thread: searching microsoft acces database using vb 2008
- Next Thread: Basketball Simulator
| Thread Tools | Search this Thread |
.net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dropdownlist excel fade file-dialog folder ftp generatetags google gridview hardcopy image images input insert intel internet mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 port print problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





