Your comment "I get an error" is too generic of a scenario.
Use the Try... Catch Block to catch the error being thrown. This will
help you troubleshoot and search for help online via docs and forums.
Verify your SQL statement. Set Break point prior to executing Fill
statement. Step through your code as your sql command is built and
hover mouse over your final SQL statement to verify the correct sql
syntax or use the sql query builder to verify that your sql statement is
producing an output.
Here is a generic Try...Catch block the will give you some idea of the
source of the error being thrown.
Try
'Put your code here
Catch oExcept As Exception
MessageBox.Show(oExcept.Message)
End Try
For example: Set break point at beginning of DataInsert Sub and step
through the Sub. Hover mouse over sSQL as it is Built.
Private Sub DataInsert()
Dim ocmd As OleDbCommand
Dim sSQL As String
Dim intRows As Integer
sSQL = "INSERT INTO Patient (LN, FN, FullName, DOB , SSN) "
sSQL &= "VALUES ("
sSQL &= Str2Field(txtLN.Text) & ", "
sSQL &= Str2Field(txtFN.Text) & ", "
sSQL &= Str2Field(txtFullName.Text) & ", "
sSQL &= Str2Field(txtDOB.Text) & ","
sSQL &= Str2Field(txtSSN.Text) & ")"
Try
ocmd = New OleDbCommand()
With ocmd
.Connection = New _
OleDbConnection(ConnectStringBuild())
.Connection.Open()
.CommandText = sSQL
intRows = .ExecuteNonQuery()
If intRows <> 1 Then
MessageBox.Show("Did not Insert row")
txtLN.Focus()
txtLN.Select()
Exit Sub
Else
MessageBox.Show("Patient was successfully Added!!")
btnInsert.Enabled = False
txtSearch.Text = txtLN.Text
lstPatient.Items.Clear()
txtPID.Text = ""
txtLN.Text = ""
txtFN.Text = ""
txtFullName.Text = ""
txtDOB.Text = ""
txtSSN.Text = ""
btnSearch.Focus()
End If
.Connection.Close()
End With
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
End Sub
Hope this helps
Mike
-----Original Message-----
From: marl@s... [mailto:marl@s...]
Sent: Thursday, February 20, 2003 4:47 PM
To: ADO.NET
Subject: [ado_dotnet] SqlDataAdapter <- No Records What Now?
Hi:
I enter a sql statement which happens to return no records.
When I try the SqlDataAdapter's Fill method I get an error.
I've looked in docs and can't find this scenario.
What am I supposed to do?
===
Fast Track ADO.NET with C# is a concise introduction to the concepts,
techniques, and libraries that you will need in order to start using
ADO.NET in your applications. The book covers DataSets and Typed
DataSets, accessing data using DataReaders and DataAdaptors, the close
relationship between ADO.NET and XML, how and where to use ADO.NET in
your enterprise applications, and how to use Web Services and ADO.NET to
easily pass data between applications.
http://www.wrox.com/books/1861007604.htm