Hi forumites,
Please I noticed that whenever I save details of an item on my windows form on sqlserver database. I noticed that I don't see the save details until after have closed the windows form and run it again. Pls how do I do it that I can see the saved details without having to close the form and run it again. My vb.net codes are below:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
If cboItemSerialNo.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboItemName.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtPartNo.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtSellingPrice.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtSellingPrice.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtCostPrice.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtCostPrice.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboQuantity.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboQuantity.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon. Error)
Exit Sub
Else
Adapter = New SqlDataAdapter("SELECT * FROM Products", MyConn)
scb = New SqlCommandBuilder(Adapter)
ds = New DataSet
Adapter.Fill(ds, "Products")
Dim DT As DataTable = ds.Tables(0)
Dim DR As DataRow = DT.NewRow
DR("ItemSerialNo") = cboItemSerialNo.Text
DR("ItemName") = cboItemName.Text
DR("PartNo") = txtPartNo.Text
DR("SellingPrice") = txtSellingPrice.Text
DR("CostPrice") = txtCostPrice.Text
DR("Quantity") = cboQuantity.Text
DT.Rows.Add(DR)
Adapter.Update(ds, "Products")
MessageBox.Show("Product Details Saved")
End If
Catch ex As Exception
'MessageBox.Show(ex.Message)
Exit Sub
Finally
MyConn.Close()
Adapter = Nothing
scb = Nothing
ds = Nothing
End Try
End Sub
Please I noticed that whenever I save details of an item on my windows form on sqlserver database. I noticed that I don't see the save details until after have closed the windows form and run it again. Pls how do I do it that I can see the saved details without having to close the form and run it again. My vb.net codes are below:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
If cboItemSerialNo.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboItemName.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtPartNo.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtSellingPrice.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtSellingPrice.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtCostPrice.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf txtCostPrice.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboQuantity.Text = "0.00" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf cboQuantity.Text = "" Then
MessageBox.Show("Please Fill All Fields", "ALERT PROMPT", MessageBoxButtons.OK, MessageBoxIcon. Error)
Exit Sub
Else
Adapter = New SqlDataAdapter("SELECT * FROM Products", MyConn)
scb = New SqlCommandBuilder(Adapter)
ds = New DataSet
Adapter.Fill(ds, "Products")
Dim DT As DataTable = ds.Tables(0)
Dim DR As DataRow = DT.NewRow
DR("ItemSerialNo") = cboItemSerialNo.Text
DR("ItemName") = cboItemName.Text
DR("PartNo") = txtPartNo.Text
DR("SellingPrice") = txtSellingPrice.Text
DR("CostPrice") = txtCostPrice.Text
DR("Quantity") = cboQuantity.Text
DT.Rows.Add(DR)
Adapter.Update(ds, "Products")
MessageBox.Show("Product Details Saved")
End If
Catch ex As Exception
'MessageBox.Show(ex.Message)
Exit Sub
Finally
MyConn.Close()
Adapter = Nothing
scb = Nothing
ds = Nothing
End Try
End Sub