Hi I am trying to update my database based on the selected values in two comboboxes.
Combobox1 = Manufacturers
Combobox2 = Orderlists
In the App the user selects a manufacturer and then an orderlist and then presses Ok button which updates the default orderlist for the manufacturer.
I am having problems on buttonClick event which updates the data, just unsure of method, if somebody could even point me towards a good tutorial it would be great as I have searched high and low for one.
thanks very much
Dwayne
Code is as follows....
Imports System.Data
Imports System.Data.SqlClient
Public Class frmMain
Dim ConnString As String = "Server=MACHINENAME\SQL2008EX;Database=mydb;Trusted_Connection=True;"
Dim SQLCon As New SqlConnection(ConnString)
Private Sub TabPage2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage2.Click
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SQLCmd As String = "SELECT ManufacturerID, Name FROM Manufacturer ORDER BY Name"
Dim da As New SqlDataAdapter(SQLCmd, SQLCon)
Dim ds As New DataSet
'Fill the dataset
da.Fill(ds, "MakersList")
With ComboBox1
.DataSource = ds.Tables("MakersList")
.DisplayMember = "Name"
.ValueMember = "ManufacturerID"
.SelectedIndex = 0
End With
Dim SQLCmd2 As String = "SELECT OrderListID, OrderListCode, OrderListDescription FROM OrderList ORDER BY OrderListCode"
Dim da2 As New SqlDataAdapter(SQLCmd2, SQLCon)
Dim ds2 As New DataSet
'Fill the dataset
da2.Fill(ds2, "OrderLists")
With ComboBox2
.DataSource = ds2.Tables("OrderLists")
.DisplayMember = "OrderListDescription"
.ValueMember = "OrderListCode"
.SelectedIndex = 0
End With
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim SQLCmd As String = "Update(Stock)SET DefaultOrderListID = '" & ComboBox2.SelectedValue & "' WHERE StockID IN(SELECT DISTINCT StockID FROM StockManufacturer WHERE ManufacturerID = '" & ComboBox1.SelectedValue & "')"
Dim da As New SqlDataAdapter(SQLCmd, SQLCon)
Dim ds As New DataSet
Dim dt As New DataTable
'Update the DB
da.Update(dt)
MessageBox.Show("Query Completed")
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
End Class