retrieving a single piece of data from a dataset

M

Mike Fellows

im trying (with great difficulty) to retrieve 1 item of data from a dataset

im trying to put the piece of data into a string from column 0 row 1

here is my code (i guess you will see what im trying to achieve)




Private Function checkduplicate(ByVal Surname As String, ByVal Firstname As
String, ByVal HouseNo As String, ByVal StreetName As String, ByVal Postcode
As String)


Dim conn As New System.Data.SqlClient.SqlConnection(SQLstrConn)
Dim sql As String = "CheckDuplicate '" & Surname & "','" & Firstname
& "','" & HouseNo & "','" & StreetName & "','" & Postcode & "'"
Dim da As New System.Data.SqlClient.SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds)
Dim RowCount As Integer = ds.Tables(0).Rows.Count
Dim ID As String


I need to set ID equal to column 0 row 1 here

If RowCount = 1 Then
Return ID
Else
Return "Record Does Not Exist"
End If


End Function


Thanks

Mike
 
M

Marina

Sorry, I actually don't see what you are trying to do, other then to make
sure that at least one record came back.

But to get the first column of the first row, you would use
ds.Tables(0).Rows(0)(0). If there were no rows, this of course would throw
an exception.

Also, if all you need is one piece of information, consider using
ExecuteScalar of the SqlCommand object. If you really just need 1 piece of
information and that's it, filling a dataset is overkill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top