there is another problem that i am facing..i got 2 comboboxes filled with values from MS Access and they have values like 1.00,2.00,2.98,3.00,3.25 and 8.00

I want to be able to choose 2 values i.e. one value from each combo box and when I hit click I should get queries which have RAM values equal to and between the 2 chosen values from the combobox..

this query does not get executed and I get the error of datatype mismatch..i have been breaking my head to solve this but all in vain.. can u help me with this one also pls!!

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 '" CDec(ComboBox6.SelectedItem) "' and '" CDec(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

hello,

>>> "select * from table1 where RAM between ... "

Never use *, the sign of slackers! You must always enumerate only those columns you really need for your datagrid!

There are lots of reasons for data type mismatch, so it s better you bring in the complete and exact error message.

----
tesu

Thanks Tesuji.. I got it!! Appreicate ur help..

I have one other problem in my code..if you can take a look at it..would be great..

I have a couple of combo boxes. Any combination chosen from the combobox works. I am getting 2 errors in it.

error1: When I chose RAM as 2.98 i get 4 results

but when i chose RAM as 8 I get 2 records of 8 gb and the 4 results of 2.98 too! why is that ?

error2 : when i dont choose anything atall from any of the combo boxes, and just hit "click" in the form, the form still displays a few records in the datagridview.!

pls advise !!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=Z:\CAD\Copy of USERS.mdb")

Dim cmd As New OleDbCommand

cmd = New OleDbCommand("Select * from table1 Where Mfg Like '%" & ComboBox1.SelectedItem & "%' And Make Like '%" & ComboBox2.SelectedItem & "%' And RAM Like '%" & ComboBox3.SelectedItem & "%' And GraphicsCard Like '%" & ComboBox4.SelectedItem & "%' And GraphicsVersion Like '%" & ComboBox5.SelectedItem & "%'", con)

con.Open()

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Try

Dim ds As DataSet = New DataSet()

ds.Tables.Add("table1")

da.Fill(ds, "table1")

DataGridView1.DataSource = ds.Tables("table1").DefaultView

Finally

con.Close()

cmd = Nothing

da.Dispose()

con.Dispose()

End Try

End Sub

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

con.Open()

If (ComboBox6.SelectedItem = Nothing) Or (ComboBox7.SelectedItem = Nothing) Then

MsgBox(" Please choose 2 values")

Exit Sub

End If

cmd1 = New OleDbCommand("select * from table1 where RAM >= (" & ComboBox6.SelectedItem & " ) and RAM <= (" & 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

i got it..i just had to take off both the % signs from RAM's like statement..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.