|
-
Jun 4th, 2005, 08:53 PM
#1
Thread Starter
New Member
dataset 101
Hi all
Just doing my first VB.net project for Uni and have come a bit stuck using a dataset...if anybody has some advice I would appreciate it.
I have a form that has a dataAdapter on it (OleDbDataAdapter3) which I have configured with a WHERE statement based on ItemID which I get from a text box. I want to get the other data from the dataset (dataset11) such as the description field, the title etc. I can do this by binding a textbox (did that to make sure the DataAdapter WHERE statement was working...however I was wondering if there is a way to use the dataset data straight into a variable. I tired the following...
strDescription = Me.txtDescription.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSet11, "Items.Description"))
but I get the error message saying "this expression does not produce a value". Is there an easy way to get the value from a dataset? I can post more code if it's helpful...
thanks in advance
cameron
-
Jun 5th, 2005, 12:34 AM
#2
Re: dataset 101
Just by looking at the names of the dataset and dataadapter, I'm pretty sure you're using the drag and drop method of creating your datasets. I am not very familiar with that method, and neither are a lot of the members here. We prefer handcoding it.
Here's a simple example with a sqldataadapter:
VB Code:
Dim da As SqlClient.SqlDataAdapter
Dim strSQL As String
Dim strConn As String
strConn = "Data Source=(local); Initial Catalog=Northwind; User ID=sa;"
strSQL = "SELECT * FROM Products"
ds = New DataSet
Try
da = New SqlClient.SqlDataAdapter(strSQL, strConn)
da.Fill(ds, "Products")
TextBox1.text = ds.Tables(0).Rows(0).Item(4).ToString()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try
-
Jun 5th, 2005, 01:10 AM
#3
Thread Starter
New Member
Re: dataset 101
Cheers
it's the drag and drop that is making the whole thing hard I think....it's the way the lecturer reccomended doing it...however just looking at your code it's clearer what is actually happening so think I will make the switch to handcoding
thanks for the assistance
cameron
-
Jun 5th, 2005, 01:12 AM
#4
Re: dataset 101
That's why I reccommended this method. It helps you understand what actually is going on. I do not understand why your lecturer would reccommend this, but hey, to each his own.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|