Sql server connection using code in VB.NET

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

Join Date: Jul 2007
Posts: 1
Reputation: edcaryl is an unknown quantity at this point 
Solved Threads: 0
edcaryl edcaryl is offline Offline
Newbie Poster

Sql server connection using code in VB.NET

 
0
  #1
Jul 23rd, 2007
Hi,

Does anyone have some good examples of ADO.NET code that demonstrates a coded connection to SQL Server such that bound controls bind to retrieve and update data.

Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,432
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster
Join Date: Aug 2006
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Sql server connection using code in VB.NET

 
1
  #3
Jul 24th, 2007
Try this

"Mod Alert" - Move the thread to VB.NET Forum.
There is just two ways to live your life.
One is as though nothing is a miracle.
The other is as if everything is.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1
Reputation: MarianaM is an unknown quantity at this point 
Solved Threads: 0
MarianaM MarianaM is offline Offline
Newbie Poster

Re: Sql server connection using code in VB.NET

 
0
  #4
Jul 31st, 2007
Originally Posted by edcaryl View Post
Hi,

Does anyone have some good examples of ADO.NET code that demonstrates a coded connection to SQL Server such that bound controls bind to retrieve and update data.

Thanks
try this:
Dim SQLConn As SqlConnection = New SqlConnection
SQLConn.ConnectionString = "Data Source=servername;" & _
"Initial Catalog=databasename;" & _
"User ID=username;" & _
"Password=userpassword;"
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 2
Reputation: kap_sharma is an unknown quantity at this point 
Solved Threads: 0
kap_sharma kap_sharma is offline Offline
Newbie Poster

Re: Sql server connection using code in VB.NET

 
0
  #5
Aug 2nd, 2007
the easy and best way to get connected with sql server is given below:-

"declare this in the code window on a form. this should be first line in the the code window, import the library class."

import system.data.sqlclient

"then declare these publically"

dim con as sqlconnection
dim cmd as sqlcommand
dim rs as recordset
dim da as sqldataadaptor

"on form load make the connection:"

con= new sqlconnection("connection string")
con.open
msgbox"ok"

"you are connected with sql server"

still you have any query pls mention.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 23
Reputation: bruce2424 is an unknown quantity at this point 
Solved Threads: 0
bruce2424 bruce2424 is offline Offline
Newbie Poster

Re: Sql server connection using code in VB.NET

 
0
  #6
Nov 12th, 2008
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)

http://vb.net-informations.com/dataa...-sqlserver.htm
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 155
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Sql server connection using code in VB.NET

 
0
  #7
Nov 14th, 2008
First you must buy a Book, i think every .NET Books that i have ever read they cover that part .

http://www.codeproject.com/KB/cs/NTier.aspx

http://www.codeproject.com/KB/cs/N-Tier22.aspx

http://www.codeproject.com/KB/vb/N-T...cation_VB.aspx

Thank you
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: Sql server connection using code in VB.NET

 
0
  #8
Nov 15th, 2008
A simple code on how to connect sql server from VB.Net via SQL connection string, and the use of ExecuteNonQuery() method to execute the command and the try and catch to catch errors during runtime.

Example information:

SQL data:

Database name: user

Table name: user_t

Columns: user_id,lname,fname,username,password,usertype


Controls:

textboxes:

textID= for Id

textlname = for last name

textfname = for first name

textusername = for user name

textpassword = for password

combobox:

comboUsertype = for user type


Code:

Dim con As New SqlClient.SqlConnection

Dim strCon as string = "Data Source=servername;Initial Catalog=user;Integrated Security=True"

Dim strCommand As String = "Insert into user_t (user_id, lname, fname, username, password, usertype) values ('" & Me.textID.text & "','" & Me.textlname.text & "', '" & Me.fname.text & "', '" & Me.textusername.text & "','" & Me.textpassword.text & "','" & Me.comboUsertype.text & "')"

Sub insert()

Try

con.ConnectionString = strCon

Dim cm As New SqlClient.SqlCommand(strCommand, con)

con.Open()

cm.ExecuteNonQuery()

MsgBox("Succesfully saved…")

Catch ex As Exception

MessageBox.Show(ex.Message, "Error")

Finally

If con.State = ConnectionState.Open Then

con.Close()

End If

End Try

End sub
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 1
Reputation: Tseli is an unknown quantity at this point 
Solved Threads: 0
Tseli Tseli is offline Offline
Newbie Poster

Re: Sql server connection using code in VB.NET

 
0
  #9
Nov 20th, 2008
Hi, im trying to save,update and delete records from access database using vb 2005, Please help wit the ciding
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: Sql server connection using code in VB.NET

 
0
  #10
Nov 20th, 2008
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC