For adding a new record using command builder i have used the following code:
CODE
Dim conString As String = "Data Source= Ankita; Initial Catalog=Ankita; Integrated Security=True"
Dim conn As SqlConnection = New SqlClient.SqlConnection(conString)
Dim str As String
str = "Select * from RawMaterial"
Dim ds As New DataSet
Dim da As New SqlDataAdapter(str, conn)
Dim sc As New SqlCommand
Dim cb As New SqlCommandBuilder(da)
Dim NewRow As DataRow
Dim inc As Integer
da.Fill(ds, "RawMaterial")
If inc <> -1 Then
NewRow = ds.Tables("RawMaterial").NewRow()
NewRow.Item("RawMaterialCode") = cboRawMaterialCode.Text
NewRow.Item("RawMaterialName") = txtRawMaterialName.Text
NewRow.Item("RawMaterialManufacturer") = txtManufacturer.Text
NewRow.Item("RawMaterialQuantity") = txtQuantityofRawMaterial.Text
NewRow.Item("RawMaterialRate") = txtRawMaterialRate.Text
'NewRow.Item("DateofPurchase") = txtDateofPurchase.Text
ds.Tables("RawMaterial").Rows.Add(NewRow)
da.Update(ds, "RawMaterial")
MsgBox("New Record added to the Database")
It Works Perfectly.
For deleting i have used the following code:
CODE
'Dim conString As String = "Data Source= Ankita; Initial Catalog=Ankita; Integrated Security=True"
'Dim conn As SqlConnection = New SqlClient.SqlConnection(conString)
'Dim Str As String
'Str = "Select * from RawMaterial"
'Dim ds As New DataSet
'Dim da As New SqlDataAdapter(Str, conn)
'Dim cb As New SqlCommandBuilder(da)
'da.Fill(ds, "RawMaterial")
'ds.Tables("RawMaterial").Rows(0).Delete()
'da.Update(ds, "RawMaterial")
'MsgBox("Record has been deleted from the Database")
But i dont want this code because it deletes as per the row specified in the following line.
"'ds.Tables("RawMaterial").Rows(0).Delete()"
I want to delete as per the Item selected in the combo box using command builder as i did the adding.
Please help.