Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,072 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,793 people online right now. Registration is fast and FREE... Join Now!




access db

 
Reply to this topicStart new topic

access db, error in code

a_a_s
5 Mar, 2008 - 10:34 AM
Post #1

D.I.C Head
**

Joined: 20 Feb, 2008
Posts: 67

i hope you can solve this problem
i want to read from db and display the readed record in combox
but their are error


vb

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Dim g1 As String
ComboBox2.Items.Clear() 'refresh combo sem
g1 = ComboBox1.Text
Dim MyCmd As New OleDbCommand
Dim MyReader As OleDbDataReader
con.Open()

MyCmd.Connection = con
MyCmd.CommandType = CommandType.Text
MyCmd.CommandText = "select DISTINCT CourseID from Course where LevelNo='" & g1 & "'"
MyReader = MyCmd.ExecuteReader

Do While MyReader.Read
ComboBox2.Items.Add(MyReader.GetString("0")) 'this statment select only 1 (0)coulmn in table
Loop
MyReader.Close()
con.Close()
End Sub


the error is Data type mismatch in criteria expression. in the statement (MyReader = MyCmd.ExecuteReader)

This post has been edited by PsychoCoder: 5 Mar, 2008 - 10:42 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Access Db
5 Mar, 2008 - 10:45 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Is your LevelNo column of INT data type? If so your SQL statement is incorrect because you are passing in a string , change your SQL statement to

vb

MyCmd.CommandText = "select DISTINCT CourseID from Course where LevelNo=" & g1


Also, I believe you have your sequence out of order, you need to setup your SqlCommand Object before you open your connection, like:


vb

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim g1 As String
ComboBox2.Items.Clear() 'refresh combo sem
g1 = ComboBox1.Text
Dim MyCmd As New OleDbCommand
Dim MyReader As OleDbDataReader
MyCmd.Connection = con
MyCmd.CommandType = CommandType.Text
MyCmd.CommandText = "select DISTINCT CourseID from Course where LevelNo='" & g1 & "'"
con.Open()
MyReader = MyCmd.ExecuteReader
Do While MyReader.Read
ComboBox2.Items.Add(MyReader.GetString("0")) 'this statment select only 1 (0)coulmn in table
Loop
MyReader.Close()
con.Close()
End Sub

User is offlineProfile CardPM
+Quote Post

a_a_s
RE: Access Db
5 Mar, 2008 - 11:10 AM
Post #3

D.I.C Head
**

Joined: 20 Feb, 2008
Posts: 67

YES ,IT IS number in the db
who can i convert it

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Access Db
5 Mar, 2008 - 11:26 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You don't need to convert it, look at the changes I made to your SQL statement, I removed the single quotes ('') from around it. Did you try the code I provided?
User is offlineProfile CardPM
+Quote Post

a_a_s
RE: Access Db
5 Mar, 2008 - 11:35 AM
Post #5

D.I.C Head
**

Joined: 20 Feb, 2008
Posts: 67

thank you so much i take long time trying solving it
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Access Db
5 Mar, 2008 - 12:02 PM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
No problem, glad I could help smile.gif
User is offlineProfile CardPM
+Quote Post

sadikcode
RE: Access Db
5 Mar, 2008 - 12:44 PM
Post #7

New D.I.C Head
*

Joined: 5 Mar, 2008
Posts: 1

try this


vb

'create a connection using a class Named "MainConn"
Public Class MainConn
Public Shared strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Video.mdb;Persist Security Info=False;"

End Class

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private Sub Payment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn As New OleDbConnection(MainConn.strconn)
conn.Open()
Dim objReader As OleDb.OleDbCommand = New OleDb.OleDbCommand("select date from Transactions where amount=0 order by tid asc", conn)
Dim rd As OleDb.OleDbDataReader
rd = objReader.ExecuteReader()

Do While rd.Read()

cmbdate.Items.Add(rd("tid".ToString))
Loop
rd.Close()
conn.Close()

end sub


Please use code tags when posting code => code.gif

This post has been edited by PsychoCoder: 5 Mar, 2008 - 12:47 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:04PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month