User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 423,075 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,336 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 444 | Replies: 3 | Solved
Reply
Join Date: Jun 2008
Posts: 107
Reputation: kavithabhaskar is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Data Type mismatch!! :( Breaking my head on this for days!!!

  #1  
Jul 25th, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: Data Type mismatch!! :( Breaking my head on this for days!!!

  #2  
Jul 25th, 2008
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
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote  
Join Date: Jun 2008
Posts: 107
Reputation: kavithabhaskar is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Re: Data Type mismatch!! :( Breaking my head on this for days!!!

  #3  
Jul 25th, 2008
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
Reply With Quote  
Join Date: Jun 2008
Posts: 107
Reputation: kavithabhaskar is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Re: Data Type mismatch!! :( Breaking my head on this for days!!!

  #4  
Jul 25th, 2008
i got it..i just had to take off both the % signs from RAM's like statement..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 5:29 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC