2 Replies - 383 Views - Last Post: 01 December 2012 - 04:05 AM Rate Topic: -----

#1 beginner_emman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-August 12

DataType Mismatch? in vb.net

Posted 30 November 2012 - 09:34 AM

hi, can anyone please check why im getting a datatype mismatch error? here's the scenario, im using combobox then selectedvalue to get the data from database and put in the textbox.. in my MsAccess database, i have a table which consist of FormNo(autonumber) Lastname, Firstname, MiddleName (text) and address (text)...i dont have get an error when im using address as valuemember/Selectedvalue..below is the codes

	Public Sub frmLoan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	 
	     Private Sub FillCombo()
	        Try
	            Dim asql As String = ("SELECT LastName +', '+ FirstName +', '+ MiddleName  AS FullName,Address FROM tbleMember WHERE deactivate=false order by Lastname")
	            Dim da As New OleDbDataAdapter(asql, MyConn)
	            Dim ds As New DataSet
	            ds.Clear()
	            da.Fill(ds)
	            cmbName.DisplayMember = "FullName"
	            cmbName.ValueMember = "Address"
	            cmbName.DataSource = ds.Tables(0)
	            cmbName.SelectedIndex = 0
	        Catch ex As Exception
	            MsgBox("ERROR : " & ex.Message.ToString)
	        End Try
	    End Sub
	 
	Private Sub cmbName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbName.SelectedIndexChanged
	 
	       
	        Dim asql As String = ("SELECT * FROM tbleMember where deactivate=false AND Address='" & cmbName.SelectedValue.ToString & "'")
	        MyConn.Open()
	        Dim cmd As New OleDbCommand
	        cmd.CommandText = asql
	        cmd.Connection = MyConn
	        dr = cmd.ExecuteReader
	 
	        If dr.Read = True Then
	            txtShare.Text = dr("shareCapital").ToString
	            txtFormNo.Text = dr("FormNo")
	            txtAddress.Text = dr("Address")
	           
	        End If
	        MyConn.Close()
	        
	        
	    End Sub




above codes im using address in data from msaccess databse..

but if i will use FormNo as valuemember/selectedvalue in combobox changed im getting data type mismatch...see below codes

	Public Sub frmLoan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	 
	     Private Sub FillCombo()
	        Try
	            Dim asql As String = ("SELECT LastName +', '+ FirstName +', '+ MiddleName  AS FullName,FormNo FROM tbleMember WHERE deactivate=false order by Lastname")
	            Dim da As New OleDbDataAdapter(asql, MyConn)
	            Dim ds As New DataSet
	            ds.Clear()
	            da.Fill(ds)
	            cmbName.DisplayMember = "FullName"
	            cmbName.ValueMember = "FormNo"
	            cmbName.DataSource = ds.Tables(0)
	            cmbName.SelectedIndex = 0
	        Catch ex As Exception
	            MsgBox("ERROR : " & ex.Message.ToString)
	        End Try
	    End Sub
	 
	Private Sub cmbName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbName.SelectedIndexChanged
	 
	       
	        Dim asql As String = ("SELECT * FROM tbleMember where deactivate=false AND FormNo='" & cmbName.SelectedValue.ToString & "'")
	        MyConn.Open()
	        Dim cmd As New OleDbCommand
	        cmd.CommandText = asql
	        cmd.Connection = MyConn
	        dr = cmd.ExecuteReader
	 
	        If dr.Read = True Then
	            txtShare.Text = dr("shareCapital").ToString
	            txtFormNo.Text = dr("FormNo")
	            txtAddress.Text = dr("Address")
	           
	        End If
	        MyConn.Close()
	        
	        
	    End Sub



hope someone can enlighten my query..thanks guys...im stuck 4days modifying this codes... :(

Is This A Good Question/Topic? 0
  • +

Replies To: DataType Mismatch? in vb.net

#2 zeeshanef  Icon User is online

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 73
  • Joined: 14-April 12

Re: DataType Mismatch? in vb.net

Posted 30 November 2012 - 12:10 PM

deactivate=false should be deactivate='false' !
Was This Post Helpful? 0
  • +
  • -

#3 beginner_emman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-August 12

Re: DataType Mismatch? in vb.net

Posted 01 December 2012 - 04:05 AM

sir, thanks for the help..but it didnt work. im getting this error when i change the cmbName.valuemember = "FormNo" but if i use cmbName.valuemember = "address" there is no error... how come the error is datatype mismatch in criteria expression? i already tried chaning the datatype of FormNo as number from autonumber, but it is not working...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1