944,133 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 77043
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 23rd, 2007
0

Sql server connection using code in VB.NET

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
edcaryl is offline Offline
1 posts
since Jul 2007
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Jul 24th, 2007
1

Re: Sql server connection using code in VB.NET

Try this

"Mod Alert" - Move the thread to VB.NET Forum.
Reputation Points: 347
Solved Threads: 13
Practically a Posting Shark
arjunsasidharan is offline Offline
812 posts
since Aug 2006
Jul 31st, 2007
0

Re: Sql server connection using code in VB.NET

Click to Expand / Collapse  Quote originally posted by edcaryl ...
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;"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MarianaM is offline Offline
1 posts
since Jul 2007
Aug 2nd, 2007
0

Re: Sql server connection using code in VB.NET

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kap_sharma is offline Offline
2 posts
since Aug 2007
Nov 12th, 2008
0

Re: Sql server connection using code in VB.NET

connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)

http://vb.net-informations.com/dataa...-sqlserver.htm
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bruce2424 is offline Offline
23 posts
since Jun 2008
Nov 14th, 2008
0

Re: Sql server connection using code in VB.NET

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
Reputation Points: 31
Solved Threads: 14
Posting Whiz
vuyiswamb is offline Offline
310 posts
since Mar 2007
Nov 15th, 2008
1

Re: Sql server connection using code in VB.NET

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
Reputation Points: 10
Solved Threads: 9
Junior Poster
sierrainfo is offline Offline
144 posts
since May 2008
Nov 20th, 2008
0

Re: Sql server connection using code in VB.NET

Hi, im trying to save,update and delete records from access database using vb 2005, Please help wit the ciding
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tseli is offline Offline
1 posts
since Nov 2008
Nov 20th, 2008
0

Re: Sql server connection using code in VB.NET

Reputation Points: 10
Solved Threads: 9
Junior Poster
sierrainfo is offline Offline
144 posts
since May 2008

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.
This thread is currently closed and is not accepting any new replies.
Previous Thread in VB.NET Forum Timeline: SQL Server Connection in vb.net
Next Thread in VB.NET Forum Timeline: Finding file size





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


Follow us on Twitter


© 2011 DaniWeb® LLC