My code:
Private Sub FillDataSet()
Dim myConnection As SqlConnection = New SqlConnection(ConnStr)
Dim myCommand As New SqlDataAdapter("tsp_get_Accounts", myConnection)
Try
Dim myAdapter As New SqlDataAdapter()
myConnection.Open()
myAdapter.Fill(_DataSet)
myConnection.Close()
Catch ex As Exception
RecordError.Record(ex)
End Try
End Sub
it goes wrong on: myAdapter.Fill(_DataSet) with error value can not be null
anyone know why
when i run the tsp in sql query analyzer i get back the entire table...

myAdapter.Fill(_DataSet) with error value can not be null
Jan van der Peet
Dim _DataSet As New DataSet()
Private Sub FillDataSet()
Dim myAdapter As New SqlDataAdapter("tsp_get_Accounts", ConnStr)
Try
myAdapter.Fill(_DataSet)
Catch ex As Exception
RecordError.Record(ex)
End Try
End Sub
Obviously, this isn't always the solution (there are times when you DO want explicit command and connection objects, but that didn't appear to be the case in this example), but since we were all rewriting code, figured I'd add my own spin on it <g>.
mango_123
<g>
AJCodeFixer
Private Sub FillDataSet()
Dim myConnection As New SqlConnection(ConnStr)
Dim myCommand As New SqlCommand("tsp_get_Accounts", myConnection)
Dim myAdapter As New SqlDataAdapter(myCommand)
Try
myAdapter.Fill(_DataSet)
Catch ex As Exception
RecordError.Record(ex)
End Try
End Sub
RamyaPatki
Dim _DataSet As New DataSet()
Thanks,
Lan
Bernd
And I think in your example, Ken, it would definitely be OK to do it that way, even if you still needed to do something with say...the SqlCommand, like setting parameters, because you could access them through myAdapter.SelectCommand.Parameters
OK, I'm sure this is information overload, so I'm going to stop now! :p (I was about to point out how using a DAL would make things even easier :p )