Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day experts, i'm trying to run a program to populate my datagridview wherein i can edit,delete or add a new row. i have my code here but something is not right i think. when i try to add a new row, only column0 which is my ID set as s primary key and my column1 for my itemName, are added,the next column are not updated which is itemPrice. please see my code.any help is appreciated


VB
Dim da As SqlDataAdapter
   Dim cmd As SqlCommand
   Dim ds As New DataSet


''this how i populate my datagrid
VB
Dim con As New SqlConnection(ConnectString())
        con.Open()
        cmd = New SqlCommand("SELECT Id,MiscName as [Miscellaneous Name],convert(decimal(10,2),MiscPrice) as [Price] FROM Miscellaneous", con)
        da = New SqlDataAdapter(cmd)
        da.Fill(ds, "Miscellaneous")
        con.Close()
        dgvMiscList.DataSource = ds
        dgvMiscList.DataMember = "Miscellaneous"


''button to enable adding new rows
VB
dgvMiscList.ReadOnly = False
       btnSaveNewMisc.Enabled = True
       btnAddNewMisc.Enabled = False


''and this is how i update the database
VB
Dim cmdbuilder As New SqlCommandBuilder(da)
        Dim i As Integer
        Try
            i = da.Update(ds, "Miscellaneous")
            MsgBox("Records Updated= " & i)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try 
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900