Link Two Comboboxes vb net - vb.net

Combobox2 values need to be changed when combobox1 changes value
Private Sub ComboBoxPodelba_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxPodelba.SelectedIndexChanged
Dim myconnect As New SqlConnection
myconnect.ConnectionString = Common.connectionString
Dim mycommand2 As SqlCommand = New SqlCommand()
mycommand2.Connection = myconnect
Try
myconnect.Open()
mycommand2.CommandText = "select PodPodelbaIme from PodPodelba where PodelbaFK = '" + ComboBoxPodelba.SelectedValue.ToString + "'"
Dim reader2 As SqlDataReader
reader2 = mycommand2.ExecuteReader()
Dim dt2 As DataTable = New DataTable
dt2.Load(reader2)
ComboBoxPOdPodelba.ValueMember = "PodPodelbaIme"
ComboBoxPOdPodelba.DisplayMember = "PodPodelbaIme"
ComboBoxPOdPodelba.DataSource = dt2
Catch ex As Exception
End Try
End Sub

Try...
Private Sub Combo1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Combo1.SelectedIndexChanged
Dim myconnect As New SqlConnection
myconnect.ConnectionString = Common.connectionString
Dim mycommand2 As SqlCommand = New SqlCommand()
mycommand2.Connection = myconnect
Try
myconnect.Open()
mycommand2.CommandText = "select PodPodelbaIme from PodPodelba where PodelbaFK = '" + Sender.SelectedValue.ToString + "'"
Dim reader2 As SqlDataReader
reader2 = mycommand2.ExecuteReader()
Dim dt2 As DataTable = New DataTable
dt2.Load(reader2)
Combo2.ValueMember = "PodPodelbaIme"
Combo2.DisplayMember = "PodPodelbaIme"
Combo2.DataSource = dt2
Catch ex As Exception
End Try
End Sub

Related

It gives value in textbox but only after finishing it . how to display data while running timer?

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.TextBox1.Text = "hello"
Dim connectionString As String = "Data Source=192.168.0.199;Initial Catalog=NEWDATABASE;Persist Security Info=True;User ID=admin;Password=123456"
Dim connection As New SqlConnection(connectionString)
connection.Open()
Dim sql As String = "SELECT TOP (" & topvalue & ") * FROM [NEWDATABASE].[dbo].[MachineParameter] WHERE status = '0' ORDER BY Id ASC"
Dim dataadapter As New SqlDataAdapter(sql, connection)
Dim ds As New DataSet()
dataadapter.Fill(ds, "table")
DataGridViewtx.DataSource = ds
DataGridViewtx.DataMember = "table"
connection.close()
end sub

Cascading ComboBoxes

I am trying to create a cascading ComboBox that is populated from a SQL data set.
My problem is I am not getting any errors when compiling the code. but the two ComboBoxes are not populating as intended with data. Can you help me find where I am making the mistake?
Private Sub FillSalesPerson()
Dim strConnString As String
strConnString = ConfigurationManager.ConnectionStrings("con").ConnectionString
Dim DS As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.Connection = DS
cmd.CommandType = CommandType.Text
cmd.CommandText = "select distinct Name,Salesperson_Code from dbo.View_Customers_With_Sales_People"
Dim objeDS As DataSet = New DataSet()
Dim dAdapter As New SqlDataAdapter
dAdapter.SelectCommand = cmd
DS.Open()
dAdapter.Fill(objeDS)
DS.Close()
ComboBox1.ValueMember = "Salesperson_Code"
ComboBox1.DisplayMember = "Name"
ComboBox1.DataSource = objeDS.Tables(0)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedValue.ToString() <> " " Then
Dim Salesperson_Code As Integer = Convert.ToInt32(ComboBox1.SelectedValue.ToString())
FillStates(Salesperson_Code)
'ComboBox2.SelectedIndex = 0'
End If
End Sub
Private Sub FillStates(Salesperson_Code As Integer)
Dim strConnString As String = ConfigurationManager.ConnectionStrings("con").ConnectionString
Dim DS As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.Connection = DS
cmd.CommandType = CommandType.Text
cmd.CommandText = "Select [No_],[Company Name] from [dbo].[View_Customers_With_Sales_People] where (Salesperson_Code= #Salesperson_Code)"
cmd.Parameters.AddWithValue("#Salesperson_Code", Salesperson_Code)
Dim objDs As New DataSet()
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = cmd
DS.Open()
adapter.Fill(objDs)
DS.Close()
If objDs.Tables(0).Rows.Count > 0 Then
ComboBox2.ValueMember = "[No_]"
ComboBox2.DisplayMember = "[Company Name]"
ComboBox2.DataSource = objDs.Tables(0)
End If
End Sub
Try changing ComboBox1.DataSource = objeDS.Tables(0) for ComboBox1.RowSource = objeDS.Tables(0)

adding to my arraylist with out overriding it in vb

i just asked a question and i modified my my code accordingly. Something is very wrong with the way im writting my page load. my aim is to initialize the array only the first time and then to keep on incrementing it. can you help?
This is the code I used:
Imports AjaxControlToolkit
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Shtick
Inherits System.Web.UI.Page
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
Dim ItemSelect As New ArrayList()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If
If Not IsPostBack Then
FillShtickList()
End If
End Sub
Protected Sub FillShtickList()
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection)
comm = New SqlCommand("SELECT RTRIM(ProductPrice) AS Price, ProductName, ProductImage, ProductID, ProductDescription FROM Products", conn)
Try
conn.Open()
reader = comm.ExecuteReader()
ShtickDataList.DataSource = reader
ShtickDataList.DataBind()
reader.Close()
Finally
conn.Close()
End Try
End Sub
'Protected Sub ShtickDataList_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ShtickDataList.ItemCreated
' 'If e.Item.ItemType = ListItemType.Item Then
' ' Dim pce As ModalPopupExtender = e.Item.FindControl("PopupControlExtender1")
' ' Dim behaviorID As String
' ' behaviorID = "pce_" & e.Item.DataItemIndex
' ' pce.BehaviorID = behaviorID
' ' Dim img As Image = e.Item.FindControl("PI")
'item select = which item was selected
Dim Quantities As New ArrayList()
Dim itemQtyOrdered As Integer
Public Sub ShtickDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ShtickDataList.ItemCommand
If e.CommandName = "ViewCart" Then
Response.Redirect("~/ShoppingCart.aspx")
End If
If e.CommandName = "addToCart" Then
Dim itemQuantity As DropDownList = e.Item.FindControl("QuantityDropDown")
itemQtyOrdered = itemQuantity.SelectedValue
ItemSelect.Add(e.CommandArgument)
Quantities.Add(itemQtyOrdered)
Session("itemInCart") = ItemSelect
Session("quantities") = Quantities
viewInvoice()
End If
End Sub
Protected Sub viewInvoice()
Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection2)
comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = #ProductID", conn)
'Dim i As Integer
'For i = 0 To ItemSelect.Count - 1
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = (ItemSelected.Count - 1)
'Next
Try
conn.Open()
reader = comm.ExecuteReader()
ViewCartlink.Text = "View Cart: (" & ItemSelected.Count & ")"
Finally
conn.Close()
End Try
End Sub
End Class
End Try
End Sub
End Class
= CType(Session("itemInCart"), ArrayList)
'al.Add(SS)
'Session.Add("itemInCart", al)
viewInvoice()
End If
End Sub
Protected Sub viewInvoice()
'Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
'Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection2)
comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = #ProductID", conn)
Dim i As Integer
For i = 0 To ItemSelect.Count - 1
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = ItemSelect(i)
Next
Try
conn.Open()
reader = comm.ExecuteReader()
ViewCartlink.Text = "View Cart: (" & ItemSelect.Count & ")"
Finally
conn.Close()
End Try
End Sub
End Class
M(ProductPrice) AS Price, ProductID, ProductName FROM Products WHERE ProductID = #ProductID", conn)
comm = New SqlCommand("Insert into orders (UserID, ProductID, quantity) values (1, #ProductID, #Quantity)", conn)
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = item
comm.Parameters.Add("#Quantity", Data.SqlDbType.Int)
comm.Parameters("#Quantity").Value = qty
'Dim i As Integer
'For i = 0 To ItemSelect.Length - 1
' comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
' comm.Parameters("#ProductID").Value = ItemSelect(i)
'Next
Try
conn.Open()
comm.ExecuteNonQuery()
'reader = comm.ExecuteReader()
'ShoppingList.DataSource = reader
'ShoppingList.DataBind()
'reader.Close()
Finally
conn.Close()
End Try
End Sub
In the code:
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If
You have a more than where you should have a less than. The arraylist only initialises when there is an item in the array. So you only initialise the array after it is initialised. WHat you need is:
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If

VB: How to bind a DataTable to a DataGridView?

I know this is a basic question that has already been answered thousand times, but I can't make it work.
I am working in Visual Studio 2010 and have two forms in my Windows Application. In the first one (Main.vb), the user enters his inputs and the calculation takes place. In the second one (DataAnalysis.vb) the calculation results are displayed.
In Main.vb, I create the temp table that will contains all the intermediary calculation steps:
Dim tableTempJDL As DataTable = New DataTable("TempJDL")
Dim column As DataColumn
column = New DataColumn("ID", GetType(System.Int32))
tableTempJDL.Columns.Add(column)
column = New DataColumn("PthObjekt", GetType(System.Double))
tableTempJDL.Columns.Add(column)
'further columns are after created using the same method
Then, in DataAnalysis.vb, I try to display the DataTable tableTempJDL into the DataGridViewBerechnung:
Public bindingSourceBerechnung As New BindingSource()
Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung
But then I don't understand how to fill the DataGridView...
Simply, you can make your table as the datasource of bindingsource in following way:
Me.bindingSourceBerechnung .DataSource = tableTempJDL
Later on, you can bind above binding source in your datagridview in following way:
Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung
Public Class Form1
Dim CON As New SqlConnection
Dim CMD As New SqlCommand
Dim dt As New DataTable
Public Sub DbConnect()
If CON.State = ConnectionState.Open Then DbClose()
CON.ConnectionString = "Data Source = yourservername;Initial Catalog=your database name;Integrated Security=True"
CON.Open()
End Sub
Public Sub DbClose()
CON.Close()
CON.Dispose()
End Sub
Public Sub enabletext()
TextBox1.Enabled = True
End Sub
Public Sub CLEARFEILDS()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
ComboBox1.DataSource = Nothing
ComboBox1.SelectedIndex = 0
DataGridView2.Rows.Clear()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Select()
TextBox4.Enabled = False
DataGridView1.Visible = False
TextBox5.Visible = False
'AUTOSEACH()
DbConnect()
Dim SELECTQUERY As String = "SELECT PROD_CODE FROM TBLPRODUCT"
Dim MYCOMMAND As New SqlCommand(SELECTQUERY, CON)
Dim MYREADER As SqlClient.SqlDataReader
MYREADER = MYCOMMAND.ExecuteReader
Prod_Code.Items.Clear()
While MYREADER.Read
Prod_Code.Items.Add(MYREADER("PROD_CODE"))
End While
DbClose()
End Sub
Public Function InvCodeGen(ByVal CurrCode As String) As String
Dim RightSix As String = Microsoft.VisualBasic.Right(Trim(CurrCode), 3)
Dim AddValue As Integer = Microsoft.VisualBasic.Val(RightSix) + 1
Dim RetValue As String
If Microsoft.VisualBasic.Len(AddValue.ToString) = 1 Then
RetValue = "00" + AddValue.ToString
ElseIf (Microsoft.VisualBasic.Len(AddValue.ToString) = 2) Then
RetValue = "000" + AddValue.ToString
Else
RetValue = AddValue.ToString
End If
Return RetValue
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
CreateNewCode()
TextBox1.Enabled = False
DataGridView1.Visible = False
TextBox5.Visible = False
ComboBox1.Visible = True
AddCustomer()
'GridView2Load(GetDataGridView2())
End Sub
Private Sub CreateNewCode()
Dim CurrCode As String = ""
'Dim NewCode As String = "INV"
Dim NewCode As Integer
Dim mySelectQuery As String = "SELECT MAX(INV_NO) AS INVNO FROM TBLINV_HEADER"
Dim myCommand As New SqlClient.SqlCommand(mySelectQuery, CON)
myCommand.CommandType = CommandType.Text
Dim myReader As SqlClient.SqlDataReader
DbConnect()
myReader = myCommand.ExecuteReader()
Do While myReader.Read()
If IsDBNull(myReader("INVNO")) Then
myReader.Close()
Dim myNewYearQuery As String = "SELECT MAX(INV_NO) AS INVNO FROM TBLINV_HEADER"
Dim myNewYearCommand As New SqlClient.SqlCommand(myNewYearQuery, CON)
myNewYearCommand.CommandType = CommandType.Text
Dim myNewYearReader As SqlClient.SqlDataReader
myNewYearReader = myNewYearCommand.ExecuteReader()
Do While myNewYearReader.Read()
CurrCode = Trim(myNewYearReader("INVNO").ToString)
Loop
myNewYearReader.Close()
Exit Do
Else
CurrCode = Trim(myReader("INVNO").ToString)
myReader.Close()
Exit Do
End If
Loop
DbClose()
NewCode = Trim(InvCodeGen(CurrCode))
TextBox1.Text = CInt(NewCode)
End Sub
Private Sub AddCustomer()
Dim dsCusCode As New DataSet
dsCusCode.Reset()
ComboBox1.Items.Clear()
Dim myCusCodeQuery As String = "SELECT CUST_CODE as Custcode FROM TBLCUSTOMER"
Dim daCusCode As New SqlClient.SqlDataAdapter(myCusCodeQuery, CON)
DbConnect()
daCusCode.Fill(dsCusCode, "TBLCUSTOMER")
DbClose()
Dim x As Integer
For x = 0 To dsCusCode.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(dsCusCode.Tables(0).Rows(x).Item("Custcode").ToString)
'TextBox3.Text = dsCusCode.Tables(0).Rows(x).Item("custname").ToString
Next
ComboBox1.SelectedIndex = -1
x = Nothing
myCusCodeQuery = Nothing
dsCusCode.Dispose()
daCusCode.Dispose()
dsCusCode = Nothing
dsCusCode = Nothing
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim Code As String
Code = ComboBox1.Text
Dim dsCode As New DataSet
dsCode.Reset()
Dim myCodeQuery As String = "SELECT cust_name as custname, cust_add1 as custadd FROM TBLCUSTOMER where Cust_Code = '" & Code & "'"
Dim daCode As New SqlClient.SqlDataAdapter(myCodeQuery, CON)
DbConnect()
daCode.Fill(dsCode, "TBLCUSTOMER")
DbClose()
TextBox2.Text = dsCode.Tables(0).Rows(0).Item("custname").ToString
TextBox3.Text = dsCode.Tables(0).Rows(0).Item("custadd").ToString
myCodeQuery = Nothing
dsCode.Dispose()
daCode.Dispose()
dsCode = Nothing
dsCode = Nothing
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
For I As Integer = 0 To DataGridView2.Rows.Count - 1
Dim MYQUERY As String = "SELECT PROD_DESC , PROD_PRICE FROM TBLPRODUCT WHERE PROD_CODE='" & DataGridView2.Rows(I).Cells(1).Value & "'"
Dim MYCOMMAND As New SqlCommand(MYQUERY, CON)
DbConnect()
Dim MYREADER As SqlClient.SqlDataReader
MYREADER = MYCOMMAND.ExecuteReader
If MYREADER.Read() Then
DataGridView2.Rows(I).Cells(2).Value = MYREADER("PROD_DESC")
DataGridView2.Rows(I).Cells(3).Value = MYREADER("PROD_PRICE")
End If
DbClose()
Next
End Sub
Private Sub DataGridView2_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView2.CellFormatting
DataGridView2.Rows(e.RowIndex).Cells(0).Value = CInt(e.RowIndex + 1)
End Sub
Private Sub DataGridView2_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellEndEdit
For I As Integer = 0 To DataGridView2.Rows.Count - 1
Dim QTY As Double = DataGridView2.Rows(I).Cells(4).Value
Dim PRICE As Double = DataGridView2.Rows(I).Cells(3).Value
Dim AMOUNT As Double = QTY * PRICE
DataGridView2.Rows(I).Cells(5).Value = AMOUNT
Next
' SUM OF AMOUNT TOTAL
Dim COLSUM As Decimal = 0
For Each ROW As DataGridViewRow In DataGridView2.Rows
If Not IsDBNull(ROW.Cells(5).Value) Then
COLSUM += ROW.Cells(5).Value
End If
Next
TextBox4.Text = COLSUM
End Sub
'SAVE
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If MsgBox("Are you sure want to save this record?", vbYesNo + vbQuestion) = vbYes Then
updateinvheader()
updategridvalue()
CLEARFEILDS()
End If
End Sub
Private Sub updateinvheader()
Dim insertquery1 As String = "insert into TBLINV_HEADER(inv_no,inv_date,inv_cust) values(#inv_no,#inv_date,#inv_cust)"
Dim command As New SqlCommand(insertquery1, CON)
command.Parameters.AddWithValue("#inv_no", TextBox1.Text)
command.Parameters.AddWithValue("#inv_date", DateTime.Now)
command.Parameters.AddWithValue("#inv_cust", ComboBox1.Text)
DbConnect()
command.ExecuteNonQuery()
DbClose()
End Sub
Private Sub updategridvalue()
Dim i As Integer
Dim insertquery2 As String = "insert into TBLINV_detail(inv_lno,inv_no,inv_prod,inv_qty,inv_Price) values(#inv_lno,#inv_no,#inv_prod,#inv_qty,#inv_Price)"
Dim command As New SqlCommand(insertquery2, CON)
For i = 0 To DataGridView2.RowCount - 1
If DataGridView2.Rows(i).Cells(1).Value = "" Then
GoTo 100
Else
command.Parameters.AddWithValue("#inv_lno", DataGridView2.Rows(i).Cells(0).RowIndex + 1)
'command.Parameters.AddWithValue("#inv_lno", DataGridView2.Rows(i).Cells(0).)
command.Parameters.AddWithValue("#inv_no", TextBox1.Text)
command.Parameters.AddWithValue("#inv_prod", DataGridView2.Rows(i).Cells(1).Value)
command.Parameters.AddWithValue("#inv_qty", DataGridView2.Rows(i).Cells(4).Value)
command.Parameters.AddWithValue("#inv_Price", DataGridView2.Rows(i).Cells(3).Value)
End If
DbConnect()
command.ExecuteNonQuery()
DbClose()
100: command.Parameters.Clear()
Next
MsgBox("data saved successfuly")
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
DataGridView1.Visible = True
TextBox5.Visible = True
ComboBox1.Visible = False
DbConnect()
Dim MYQUERY As String = "Select * FROM TBLCUSTOMER" &
" INNER Join TBLINV_HEADER ON TBLINV_HEADER.INV_CUST = TBLCUSTOMER.CUST_CODE" &
" WHERE TBLINV_HEADER.INV_NO ='" & TextBox1.Text & "'"
Dim CMD As New SqlCommand(MYQUERY, CON)
Dim DA As New SqlDataAdapter
DA.SelectCommand = CMD
Dim DT As New DataTable
DA.Fill(DT)
If DT.Rows.Count > 0 Then
MsgBox(DT.Rows(0)(1).ToString())
'ComboBox1.Text = DT.Rows(0)(1).ToString()
ComboBox1.Visible = False
TextBox5.Text = DT.Rows(0)(1).ToString()
TextBox2.Text = DT.Rows(0)(2).ToString()
TextBox3.Text = DT.Rows(0)(3).ToString()
End If
DbClose()
DataGridView1.DataSource = GETPRODUCTDETAILS()
End Sub
Private Function GETPRODUCTDETAILS() As DataTable
Dim PRODUCTDET As New DataTable
DbConnect()
Dim MYQUERY As String = " SELECT TBLINV_DETAIL.INV_LNO, TBLINV_DETAIL.INV_PROD, TBLPRODUCT.PROD_DESC, TBLINV_DETAIL.INV_PRICE, TBLINV_DETAIL.INV_QTY, (TBLINV_DETAIL.INV_QTY*TBLINV_DETAIL.INV_PRICE) AS AMOUNT FROM TBLINV_DETAIL " &
" INNER JOIN TBLPRODUCT On TBLPRODUCT.PROD_CODE = TBLINV_DETAIL.INV_PROD " &
" WHERE TBLINV_DETAIL.INV_NO='" & TextBox1.Text & "'"
Dim CMD As New SqlCommand(MYQUERY, CON)
Dim READER As SqlDataReader = CMD.ExecuteReader()
PRODUCTDET.Load(READER)
DbClose()
Return PRODUCTDET
End Function
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim DELETEQUERY As String = "DELETE FROM TBLINV_DETAIL WHERE TBLINV_DETAIL.INV_NO= '" & TextBox1.Text & "'"
Dim DELETEQUERY2 As String = "DELETE FROM TBLINV_HEADER WHERE TBLINV_HEADER.INV_NO= '" & TextBox1.Text & "'"
Dim CMD As New SqlCommand(DELETEQUERY, CON)
Dim CMD2 As New SqlCommand(DELETEQUERY2, CON)
DbConnect()
CMD.ExecuteNonQuery()
CMD2.ExecuteNonQuery()
DbClose()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
ComboBox1.DataSource = Nothing
DataGridView1.DataSource = Nothing
MsgBox("DATA DELETED SUCCESSFULLY")
End Sub
End Class

how to display the data with combo box

Sub CboSO_DropDown(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboSO.DropDown
If functionmode = "UPDATE" Then
Dim daProp2 As New OdbcDataAdapter()
Dim dsProp2 As New DataSet()
Dim qryProp2 As String
qryProp2 = "SELECT num FROM so WHERE scn = '" & txtSCN.Text & " '"
daProp2.SelectCommand = New OdbcCommand(qryProp2, conn)
Dim cb2 As OdbcCommandBuilder = New OdbcCommandBuilder(daProp2)
daProp2.Fill(dsProp2, "so")
Dim dtRbt As DataTable = dsProp2.Tables("so")
Try
If dsProp2.Tables(0).Rows.Count > 0 Then
CboSO.DropDownStyle = ComboBoxStyle.DropDownList
CboSO.DataSource = dsProp2
CboSO.DisplayMember = "num"
End If
Catch ex As OdbcException
MsgBox(ex.ToString)
Finally
conn.Close()
End Try
End If
End Sub
Assign the DataTable object reference.
CboSO.DataSource = dtRbt
CboSO.DisplayMember = "num"