visual studio 2005 database code
Hi everyone,
I searched the forums for a possible answer to a problem that I'm having but I didn't find exactly what I was looking for.
The problem that I'm having is that I work a lot with Visual Basic 6 and I'm switching over to Visual Studio 2005 and there is a code sequence that I want to do in visual studio 2005 and I know that I have to change some of the code but I don't know how. Below I will post the VB 6 code:
Dim cn As Connection
Set cn = New Connection
cn.Open xConnString
Dim rs As Recordset
Set rs = New Recordset
rs.Open "tblAlgemeen", cn, adOpenDynamic, adLockOptimistic
'x_Max = rs("SLEUTEL")
'x_rekno = rs("REKNO")
x_kapitaal = rs("BEL_KAP")
xdt_kapitaal = rs("DT_BEL_KAP")
x_max_lening = rs("MAX_HFDSOM_LENING")
x_max_inkomen = rs("MAX_BR_INK")
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
Basicly what I'm doing in the above code is the following: make a connection with my database, retrieve one of the Tables I have in the database and put in a recordset so I can get to the data for each of my columns in the table.
My question is how can I achieve something like this in visual studio 2005 ? is there someway I can do it ?
I tried different thins with the SqlAdapter etc.. with no avail.
Thank you in advance for helping me out.
[1502 byte] By [
shagohod] at [2007-11-11 8:45:03]

# 1 Re: visual studio 2005 database code
.NET + SQL ??
SqlConnection myConnection;
SqlCommand myCommand;
SqlDataReader myDataReader;
myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
myConnection.Open();
//prepare sql statements
myCommand = new SqlCommand("SELECT TOP 10 * FROM EMPLOYEE", myConnection);
myDataReader = myCommand.ExecuteReader();
while (myDataReader.Read())
{
Console.WriteLine(myDataReader["fname"]);
Console.WriteLine(myDataReader["minit"]);
Console.WriteLine(myDataReader["lname"]);
}
There are so many ways to get the data from db..
Sync at 2007-11-11 21:47:02 >

# 3 Re: visual studio 2005 database code
thanks for the help Sync.
That part for getting the data out of the database is pretty easy, but my problem now is how to get the data in to the database.
I tried a couple of methods using data adapter and datatable but it seems that I can't get it right.
I'm kinf of lost here
# 4 Re: visual studio 2005 database code
my problem now is how to get the data in to the database
I'm not so sure that I get you.... you meant you wanna get the data from the database or you wanna insert new record into the database??
The coding above is for getting data from the database...
Sync at 2007-11-11 21:50:04 >
