Can someone please help me with this error
I have combo boxes where i populate data.
From there I take the selected value and fetch rest of the data from table to display it in datagridview.
Thanks in advance
I have combo boxes where i populate data.
From there I take the selected value and fetch rest of the data from table to display it in datagridview.
Thanks in advance
VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Public Class binsearch
Private Sub btn_binsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_binsearch.Click
Dim con As New SqlConnection("xxxx")
con.Open()
Dim cmd As New SqlCommand
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "select Cylnumber,date from [dbo].[Voltaix_BINCYL_Location] where Binnumber=" & cb_bin.SelectedValue
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
Dim dt As New DataTable()
da.Fill(dt)
Dim source As New BindingSource()
source.DataSource = dt
dgv_data.DataSource = source
con.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Connecting to the database
Dim conn As New SqlConnection("xxxxxx")
conn.Open()
Dim cmd1 As New SqlCommand()
Dim cmd2 As New SqlCommand()
cmd1.Connection = conn
cmd2.Connection = conn
cmd1.CommandType = CommandType.Text
cmd2.CommandType = CommandType.Text
cmd1.CommandText = "Select Binnumber from [dbo].[Voltaix_BINCYL_Location]"
cmd2.CommandText = "Select Cylnumber from [dbo].[Voltaix_BINCYL_Location]"
Dim da1 As New SqlDataAdapter
Dim da2 As New SqlDataAdapter
Dim dt1 As New DataTable
Dim dt2 As New DataTable
da1.SelectCommand = cmd1
da2.SelectCommand = cmd2
da1.Fill(dt1)
da2.Fill(dt2)
Dim source1 As New BindingSource()
Dim source2 As New BindingSource()
source1.DataSource = dt1
source2.DataSource = dt2
cb_bin.DataSource = source1
cb_cyl.DataSource = source2
cb_bin.DisplayMember = "Binnumber"
cb_bin.ValueMember = "Binnumber"
cb_cyl.DisplayMember = "Cylnumber"
cb_cyl.ValueMember = "Cylnumber"
'cb_cyl.SelectedIndex = 0
'cb_bin.SelectedIndex = 0
'conn.Close()
End Sub
Private Sub btn_cylsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cylsearch.Click
Dim con3 As New SqlConnection("xxxxxx")
con3.Open()
Dim cmd3 As New SqlCommand
cmd3.Connection = con3
cmd3.CommandType = CommandType.Text
'cmd3.CommandText = "select Binnumber,date from [dbo].[Voltaix_BINCYL_Location] where Cylnumber=" & cb_cyl.SelectedValue
cmd3.CommandText = "select Binnumber,date from [dbo].[Voltaix_BINCYL_Location] where Cylnumber =" & cb_cyl.SelectedItem.ToString
'cmd3.CommandText = "Select Convert(Int, ParseName(Cylnumber,2)), date from [dbo].[Voltaix_BINCYL_Location] where Binnumber=" & cb_bin.SelectedValue
Dim da3 As New SqlDataAdapter
da3.SelectCommand = cmd3
Dim dt As New DataTable()
da3.Fill(dt)
Dim source As New BindingSource()
source.DataSource = dt
dgv_data.DataSource = source
con3.Close()
End Sub
End Class