Hello all,
I'm trying to get some data from a table in an Access database, and my program is behaving weirdly (at least i think so).
Ok, so for now, i want to run this query:
Dim query As String = MonthCalendar1.SelectionStart ' + " " + ComboBox1.Text + ComboBox2.Text + " " + ComboBox3.Text
Dim myQuery1 As String = "SELECT [BID]FROM Table1 WHERE [Date]=" + query + ""
Dim myConn1 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and settings\dbase.mdb")
Dim myCommand1 As OleDbCommand = New OleDbCommand(myQuery1, myConn1)
myConn1.Open()
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader(CommandBehavior.CloseConnection)
myReader1.Read()
Dim robert As String = myReader1.ToString(0)
MsgBox(robert)
** end code
so, when i run that program, it returns the letter S, when it should be returning the word Duke.
What am I doing wrong
Any help is greatly appreciated! thanks in advance.
-Robert

Trouble with database connections
bergeron
Dim myQuery1 As String = "SELECT [BID]FROM Table1 WHERE [Date]='" + query + "'"
or
Dim myQuery1 As String = "SELECT [BID]FROM Table1 WHERE [Date]=#" + query + "#"
because both ways, the messagebox is only showing "S"
NickNotYet
Sorry for being such a nube
-Robert
CrazyEye
Unhandles exception has occured in your application. If you click Continue, the application will ignore this error and attempt to continue. if you quit, the application will close immediately.
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidOperationException: No data exists for the row/column.
at System.Data.OleDb.OleDbDataReader.DoValueCheck(Int32 ordinal)
at System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
at mcmorrow_chooser.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Robert \Local Settings\Application Data\Temporary Projects\mcmorrow chooser\Form1.vb:line 17
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
it goes on, but i think that's pretty much the most important partQuinn01
In addition to Ken's suggestion you should also get the string from the field of the reader not the reader itself...such as:
MyReader(0).ToString
or
Cstr(MyReader(0))
sofakng
NO.....From Your query string you need to include pound signs like this:
Dim query As String = "#" + MonthCalendar1.SelectionStart + "# "...
russ_mac
when i try to use this string
Dim query As String = MonthCalendar1.SelectionStart
Dim time As String = ComboBox1.Text + ComboBox2.Text + " " + ComboBox3.Text
MsgBox(time)
Dim myQuery1 As String = "SELECT [Renter]FROM Table1 WHERE [Date]=#" + MonthCalendar1.SelectionStart + "# AND [Time]=#" + time + "#"
and i try to use
MsgBox(CStr(myReader1(0))) to display it, the program throws an exception at the messagebox line!
it should be returning a string, but instead i get an exception.
sorry for being such a dweeb / annoyance / noob.
-Robert
hye_heena
Dim query As String = MonthCalendar1.SelectionStart
Dim time As String = ComboBox1.Text + ComboBox2.Text + " " + ComboBox3.Text
MsgBox(time)
Dim myQuery1 As String = "SELECT [Renter]FROM Table1 WHERE [Date]=#" + MonthCalendar1.SelectionStart + "# AND [Time]=#" + time + "#"
Dim myConn1 As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Robert\Desktop\Mcmorrow.mdb")
Dim myCommand1 As OleDbCommand = New OleDbCommand(myQuery1, myConn1)
myConn1.Open()
Dim myReader1 As OleDbDataReader = myCommand1.ExecuteReader(CommandBehavior.CloseConnection)
myReader1.Read()
'MsgBox(CStr(myReader1(0)))
If myReader1.Read Then
MsgBox(myReader1.GetString(0).ToString)
End If
George Waters
danni123
Kevin Kelly101
if myreader1.read then
dim robert as .........
end if