Is there an alternative to:
ds.Tables("TableName").Rows(0)(2).ToString()
That I can use the field name instead? Or should I just only pull the 7 or so fields in my sql statement and use the .rows parameters?
Thanks
Printable View
Is there an alternative to:
ds.Tables("TableName").Rows(0)(2).ToString()
That I can use the field name instead? Or should I just only pull the 7 or so fields in my sql statement and use the .rows parameters?
Thanks
How are you creating your dataset. If you are using visual studio you can generate strongly bound datasets that allow you to reference rows and columns through code.
I suggest you look into this. Basically the line of code you wrote would become
objdsMyDataSet.MyTable(0).MyColumn
Quote:
Originally Posted by The_Duck
This is how I am creating the set:
VB Code:
Try ds.Clear() sSQL = "SELECT * FROM Style WHERE Style_Number = @StyleNumb" da = New SqlClient.SqlDataAdapter(sSQL, conn) da.SelectCommand.Parameters.Add("@StyleNumb", stStyleNumb) conn.Open() da.Fill(ds, "Style") If ds.Tables("Style").Rows.Count <> 0 Then lblDescription.Text = ds.Tables("Style").Rows(0)(4) 'would like to replace this line by using the actual column name. Else End If Catch ex As Exception 'Handle Error Finally If conn.State = ConnectionState.Open Then conn.Close() End If End Try
Are you using visual studio?
Try adding an item called a DataSet.
That code you posted does not show how you create your dataset, only how you clear and fill it!
Sorry, Yes I am using visual studio, here is where I create the dataset:Quote:
Originally Posted by The_Duck
VB Code:
Private da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter Private ds As New DataSet
Try adding a dataset to your project then!
(From Memory)
Right Click on your Project
Choose Add New Item
Choose a dataset from the lists
What this allows you to do is define your dataset using xml (the designer will help).
Even better if add your database as a datasouce, you can drag your table onto the dataset and watch it create all the columns for you!
Even better than that it will create (when you save the dataset) all of the code necessary to access that datatable!
Good Luck!