Click here to Skip to main content
15,885,917 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a column of token no, that is data type int and in form i have a combobox its having token no 1,2,3,4.............. i want to search data on the base of token no i.e 1 but i having some error
XML
Syntax error converting the varchar value 'System.Data.DataRowView' to a column of data type int.



please help i am code which is below 
<pre lang="vb">myconn = New SqlConnection(&quot;data source=nic-bpdc;Initial Catalog=pension;integrated security=sspi;&quot;)
        myconn.Open()
        cmd.Connection = myconn
        cmd.CommandText = (&quot;select ppo_no from billentry where token_no =&#39;&quot; &amp; ComboBox1.Text &amp; &quot;&#39;&quot;)

        &#39;cmd.CommandText = (&quot;select ppo_no, p_name,sec,billdate,state from billentry where token_no =&#39;&quot; &amp; ComboBox1.Text &amp; &quot;&#39;&quot;)
        rd = cmd.ExecuteReader()
        While (rd.Read())
            TextBox5.Text = rd!ppo_no
            &#39;TextBox4.Text = rd!p_name
            &#39;&#39;TextBox3.Text = rd!billamount
            &#39;ComboBox4.Text = rd!sec
            &#39;DateTimePicker2.Text = rd!billdate
            &#39;TextBox2.Text = rd!state
        End While
        &#39;rd.Close()
        myconn.Close()</pre>
Posted
Comments
ChauhanAjay 12-Aug-14 3:42am    
can you please provide the combo box binding code also.
tanugarg 12-Aug-14 5:05am    
myconn.Open()
b = "DH"
da2 = New SqlDataAdapter("Select token_no from billentry where status = '" + b + "' and billdate=convert(datetime,'" & DateTimePicker2.Text & "',103)", myconn)
dt2 = New DataTable()
da2.Fill(dt2)
ComboBox1.DataSource = dt2
ComboBox1.DisplayMember = "token_no"
ComboBox1.ValueMember = "token_no"
If ComboBox1.SelectedIndex = -1 Then
MessageBox.Show("No Bill For Passing!")
End If

myconn.Close()
ChauhanAjay 12-Aug-14 8:30am    
In your query above please use the ComboBox1.SelectedValue.ToString() instead of ComboBox1.Text.

1 solution

ChauhanAjay gave the correct answer in a comment (use .SelectedValue, not .Text), so the question has been answered!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900