| | |
Problem in SQL statement in VB.NET.. Assistance Required.
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
Can you please tell me what's wrong with this statement ? i get no errors but I get no o/p either!
•
•
•
•
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")
If (ComboBox6.SelectedItem = 0.5) And (ComboBox7.SelectedItem) Then
Dim cmd1 As New OleDbCommand
cmd1 = New OleDbCommand("select * from table1 where RAM between 0.5000 and 2.000")
End If
End Sub
•
•
Join Date: Jan 2007
Posts: 22
Reputation:
Solved Threads: 3
Hi,
You specified the connection and command objects but you probably want a data reader...also you'll need to open the connection.
You specified the connection and command objects but you probably want a data reader...also you'll need to open the connection.
VB.NET Syntax (Toggle Plain Text)
Dim dr As OleDbDataReader dr = cmd1.ExecuteReader(CommandBehavior.Default) Do while dr.read() variablename = dr("columnName") loop
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
Hi Ripper thanks for ur reply..
the error that i get is
"Conversion from string "" to type 'Double' is not valid." at the line
"If (ComboBox6.SelectedItem = "") And (ComboBox7.SelectedItem = "") Then"
please help me rectify this problem!!
--------------------------------------------------------------------------------
KB - Knowledge is Power!
QUOTE=RipperJT;652629]Hi,
You specified the connection and command objects but you probably want a data reader...also you'll need to open the connection.
[/QUOTE]
the error that i get is
"Conversion from string "" to type 'Double' is not valid." at the line
"If (ComboBox6.SelectedItem = "") And (ComboBox7.SelectedItem = "") Then"
please help me rectify this problem!!
•
•
•
•
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")
Dim cmd1 As New OleDbCommand
If (ComboBox6.SelectedItem = "") And (ComboBox7.SelectedItem = "") Then
MsgBox("No Values have been entered ! ")
End If
cmd1 = New OleDbCommand("select * from table1 where RAM between '%" & ComboBox6.SelectedItem & "%' and '%" & ComboBox7.SelectedItem & "%'", con)
End Sub
--------------------------------------------------------------------------------
KB - Knowledge is Power!
QUOTE=RipperJT;652629]Hi,
You specified the connection and command objects but you probably want a data reader...also you'll need to open the connection.
VB.NET Syntax (Toggle Plain Text)
Dim dr As OleDbDataReader dr = cmd1.ExecuteReader(CommandBehavior.Default) Do while dr.read() variablename = dr("columnName") loop
•
•
Join Date: Jan 2007
Posts: 22
Reputation:
Solved Threads: 3
It's trying to convert the datatype on the left side to the empty string on the right side of the =. Try...
VB.NET Syntax (Toggle Plain Text)
If (ComboBox6.SelectedItem = 0) And (ComboBox7.SelectedItem = 0) Then
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
•
•
•
•
It's trying to convert the datatype on the left side to the empty string on the right side of the =. Try...
VB.NET Syntax (Toggle Plain Text)
If (ComboBox6.SelectedItem = 0) And (ComboBox7.SelectedItem = 0) Then
just curious..what does that statement do ?
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
I get the error in the "if" statement. please take a look at it..
if i hit the "click" button directly without choosing the RAM values I expect the Msg box to pop up ..instead i get an error.. ! pls see code for error../
if i hit the "click" button directly without choosing the RAM values I expect the Msg box to pop up ..instead i get an error.. ! pls see code for error../
•
•
•
•
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")
Dim cmd1 As New OleDbCommand
If (ComboBox6.SelectedItem = " ") And (ComboBox7.SelectedItem = " ") Then //error:"conversion from string"" to 'double' is not valid"
MsgBox("No Values have been entered !")
End If
cmd1 = New OleDbCommand("select * from table1 where RAM between '& ComboBox6.SelectedItem & ' and '& ComboBox7.SelectedItem & '", con)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd1)
Try
Dim ds As DataSet = New DataSet()
da.Fill(ds, "table1") //error : data type mismatch in criteria expression
DataGridView1.DataSource = ds.Tables("table1").DefaultView
Finally
con.Close()
cmd1 = Nothing
da.Dispose()
con.Dispose()
End Try
End Sub
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
Data type mismatch in criteria expression.is the error that i get at line da.Fill(ds, "table1") if i modified the code as below (after removing the"if" statement"
•
•
•
•
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")
Dim cmd1 As New OleDbCommand
cmd1 = New OleDbCommand("select * from table1 where RAM between '& ComboBox6.SelectedItem & ' and '& ComboBox7.SelectedItem & '", con)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd1)
Try
Dim ds As DataSet = New DataSet()
da.Fill(ds, "table1")
DataGridView1.DataSource = ds.Tables("table1").DefaultView
Finally
con.Close()
cmd1 = Nothing
da.Dispose()
con.Dispose()
End Try
End Sub
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
hi ripper..either way i get the same error on da.fill(ds,"table1"). that is..when i dont choose any value from either combobox and hit the click and when i choose 1 value from each of the 2 combo boxes and hit click..
yesboth my combo boxes have numbers like.2.980, 3.000,0.5000,3.000,1.000,2.000,3.250 in each of them..
pls suggest something..i have been stuck on this for weeks now..
yesboth my combo boxes have numbers like.2.980, 3.000,0.5000,3.000,1.000,2.000,3.250 in each of them..
pls suggest something..i have been stuck on this for weeks now..
•
•
Join Date: Jan 2007
Posts: 22
Reputation:
Solved Threads: 3
You can try to test to see if a value has been entered and if so then run your code.
Here's info an the function IsNumeric
http://msdn.microsoft.com/en-us/libr...w1(VS.71).aspx
VB.NET Syntax (Toggle Plain Text)
If IsNumeric(ComboBox6.SelectedItem) = True And IsNumeric(ComboBox7.SelectedItem) = True Then If ComboBox7.SelectedItem > ComboBox6.SelectedItem Then 'code here Else 'Msgbox("Ram should be selected") Exit Sub End If Else 'exit the sub 'MsgBox("blah") Exit Sub End If
Here's info an the function IsNumeric
http://msdn.microsoft.com/en-us/libr...w1(VS.71).aspx
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Error when use INSERT from VB2005 to MySQL
- Next Thread: image uploading
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





