Find connection name

BlackByte

Well-known member
Joined
Jun 29, 2008
Messages
126
Location
South Africa, Durban
Programming Experience
1-3
Hi im using vs 2005, i have learnt how connect to a database using code in vb.net, i would like to know how to use a database that was added to the project(copy and paste), i want to display the data in it. thanx
 
There is so much to know about working with databases, that this isn't a simple & direct question anyone can answer. I would suggest getting a book on the topic and going through its exercises.

However if you have a more direct question and can narrow down a more specific part of what you need help with, feel free to ask me any questions. How to work with a database has so many different options and answers though.
 
Hi thanks for the quick reply, and sorry abt my unclear question, i wanted to know how to get data from a database added as a data source, i tried using ds.tables(0).rows(0).item, but i get an error saying there's no row at position 0.

Ok I got your message & found the post. Again this seems very hard to answer only because the question seems to be so general, such as "How do you program with databases?"

But I do see an error in your last message. Accessing a datafield from any of the rows should look more like the following:

TextBox1.Text = ds.Tables(0).Rows(0)("ColumnNameHere")

But also your error message sounds like you have an additional problem of not having any data in the dataset.

Try this to check first:

VB.NET:
.

        [COLOR="blue"]If [/COLOR]ds.Tables(0).Rows.Count > 0 [COLOR="Blue"]Then[/COLOR]

            TextBox1.Text = ds.Tables(0).Rows(0)([COLOR="Red"]"ColumnNameHere"[/COLOR])

        [COLOR="blue"]Else[/COLOR]
            TextBox1.Text = ""

            MsgBox([COLOR="red"]"Table : "[/COLOR] & ds.Tables(0).TableName.ToString _
              & vbCrLf _
              & [COLOR="red"]"Record Count : " [/COLOR]& ds.Tables(0).Rows.Count.ToString)

        [COLOR="blue"]End If[/COLOR]
 
Last edited:
Hi you were right Tom, there was no data inside my dataset. i needed to fill my dataset with data using my dataAdapter, i tried this and my code now works fine. thank you.
 
Tom, it would be great if you could advise newbies who are on .NET 2 to use the type safe ways of data access, rather than old style generic ways..

myDataSet.MyDataTable(0).FirstColumn
vs
myDataSet.Tables("MyDataTable").Rows(0).Item("FirstColumn")
 

Latest posts

Back
Top