hobbes2103 Posted July 11, 2003 Posted July 11, 2003 Hello! Here is my code : Dim myConnection As New OleDb.OleDbConnection Dim myReader As OleDb.OleDbDataReader Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\erco\erco.mdb" myBase = New OleDb.OleDbConnection(myConnectionString) myBase.Open() Dim myCommand As New OleDb.OleDbCommand Dim mySelect As String = "SELECT code,name FROM articles WHERE code='1'" myCommand = New OleDb.OleDbCommand(mySelect, myBase) myReader = myCommand.ExecuteReader() Dim str As String While (myReader.Read()) str = myReader("name") End While myReader.Close() Quote
hobbes2103 Posted July 11, 2003 Author Posted July 11, 2003 Now, my problem is : if "name" is empty (it is not my primary key, so sometimes there is no name), it won't work. I would like str to get the value "". Quote
Leaders dynamic_sysop Posted July 11, 2003 Leaders Posted July 11, 2003 try this : Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.mdb;" Dim Conn As New OleDb.OleDbConnection(sConnString) Try Dim sCommand As String = "Select * From Table1" Conn.Open() Dim Command As New OleDb.OleDbCommand(sCommand, Conn) Dim reader As OleDb.OleDbDataReader reader = Command.ExecuteReader Dim x As Integer For x = 0 To reader.FieldCount - 1 MessageBox.Show(reader.GetName(x)) '/// the names of your fields. Next Catch ex As Exception MessageBox.Show(ex.Message) Finally Conn.Close() End Try End Sub it may help. Quote
*Experts* jfackler Posted July 11, 2003 *Experts* Posted July 11, 2003 Dim str As String Dim myReader As OleDbDataReader While (myReader.Read()) If Not IsDBNull(myReader("name")) Then str = myReader("name") Else str = "" End If End While myReader.Close() Jon Quote
*Gurus* Derek Stone Posted July 12, 2003 *Gurus* Posted July 12, 2003 Use [msdn=System.Data.OleDb.OleDbDataReader]OleDbDataReader[/msdn].IsDbNull(), not Visual Basic's IsDbNull() function. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.