Eddy Erman

Can anyone give me simple code for visual studios.net 2003 for a connection to a database. I have trawled through sites for 2 days now to no joy whatsoever!

thanks.



Re: Hot Technology Connect to a database

sandyk - MSFT

Your questions is probably best handled on the SQL site for future reference. That said, there are lots of examples of the code on MSDN if you look at the official documentation associated with any of the classes related to accessing SQL. For example, there's a pretty simple example that I think should be compatible with both VS2003 and VS2005 here:

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx





Re: Hot Technology Connect to a database

Salim Hemdani

Do you need configuration details or code to fetch information from database The configuration details being information on where to set database connection string and how to create "connection" OR do you need sample code to start fetching data into DataSets/SQLDataReader.

Salim Hemdani





Re: Hot Technology Connect to a database

Eddy Erman

Thankyou for the reply. I am fine with the sql i just cannot remember how the code goes to set up the connection and open the database. Here is something like what i remember of how it goes.

Dim StrSql as String
Dim Objrec as ADODB.Recordset
Dim StrConn - In here goes the microsoft jet 4.0, the path of the database and lockoptimistic etc.

StrSql = "SELECT * FROM Mydatabase.mdb WHERE Myfeild = True"
ObjRec.Open (StrConn,StrSql,,)

Thats all i can remember.





Re: Hot Technology Connect to a database

sandyk - MSFT

I think your approach is from back in the VB6 days and doesn't leverage the .NET Fx--which has concepts like DataAdapters and DataSets. I'm a C# guy, but I think the code below should do it...

Dim connection As SqlConnection = New SqlConnection(connectionString)
connection.Open()

Dim queryString As String = {SQL statement here}
Dim adapter As SqlDataAdapter = New SqlDataAdapter(queryString, connection)

Dim customers As DataSet = New DataSet
adapter.Fill(customers, "Customers")





Re: Hot Technology Connect to a database

Eddy Erman

I have figured it the code now thanks = )





Re: Hot Technology Connect to a database

Gizmod

correct is that, lot a question this asked been have i





Re: Hot Technology Connect to a database

ReneeC

Big Smile






Re: Hot Technology Connect to a database

ReneeC

I love it when someone asks a question, come back six months later and says they've figured it out and marks their question right.

I also deeply appreciate the last post. Smile






Re: Hot Technology Connect to a database

Eddy Erman

I detect sarcasm what should i have done instead





Re: Hot Technology Connect to a database

srinivaspykl

sub

dim conn as adobc.connection

set conn =new connection //giveing connection to oracle

conn.connection= " provider =MSDAORA.1; password=tiger ;user id =scott;data source=oracle persist security info=true"

conn.connectionstring //connecting

conn.open //opening a connection

dim rs as recordset //conn to a record set

rs.open("select *from student,conn.1,2") //opening a connection

rs.movefirst

rs.field(" 0")

rs.movenext

end sub