Hi everyone,
This is Tracy here.
I'm having a form created from Visual Studio 2005 and it contains a button named as Add and a DataGridview. If the records are successfully added, it will be inserted into the SQL server database.
But my program can't work and I don't know where it had gone wrong.
Here listed my codes when the user click on the "Add" button for the DataGridView:
Hope to receive reply soon as it's urgent.
This is Tracy here.
I'm having a form created from Visual Studio 2005 and it contains a button named as Add and a DataGridview. If the records are successfully added, it will be inserted into the SQL server database.
But my program can't work and I don't know where it had gone wrong.
Here listed my codes when the user click on the "Add" button for the DataGridView:
VB.NET:
'Add Button For DataGrid
Dim sqlcom As SqlCommand = New SqlCommand()
Dim mySqlDataAdapter As SqlDataAdapter
mySqlDataAdapter = New SqlDataAdapter
Dim myDataSet AsNew DataSet()
Dim mySqlcb As SqlCommandBuilder
mySqlcb = New SqlCommandBuilder(mySqlDataAdapter)
mySqlDataAdapter.InsertCommand = mySqlcb.GetInsertCommand
mySqlDataAdapter.InsertCommand.CommandText = "INSERT INTO TBReqDG(ReqID,Quantity,Description,UnitPrice,TotalPrice) VALUES(@ReqID,@Quantity,@Description,@UnitPrice,@TotalPrice)"
Dim para As SqlParameter
'para = sqlcom.Parameters.Add("@OrgReqID", SqlDbType.Int)
'para.SourceColumn = "ReqID"
'para.SourceVersion = DataRowVersion.Original
para = sqlcom.Parameters.Add("@ReqID", SqlDbType.Int, 4)
para.SourceColumn = "ReqID"
para.SourceVersion = DataRowVersion.Current
para = sqlcom.Parameters.Add("@Quantity", SqlDbType.NVarChar, 50)
para.SourceColumn = "Quantity"
para.SourceVersion = DataRowVersion.Current
para = sqlcom.Parameters.Add("@Description", SqlDbType.NVarChar, 50)
para.SourceColumn = "Description"
para.SourceVersion = DataRowVersion.Current
para = sqlcom.Parameters.Add("@UnitP", SqlDbType.NVarChar, 50)
para.SourceColumn = "UnitPrice"
para.SourceVersion = DataRowVersion.Current
para = sqlcom.Parameters.Add("@TotalP", SqlDbType.NVarChar, 50)
para.SourceColumn = "TotalPrice"
para.SourceVersion = DataRowVersion.Current
'mySqlDataAdapter.InsertCommand = ""
sqlcon.Open()
mySqlDataAdapter.InsertCommand = New SqlCommand("INSERT INTO TBReqDG(ReqID,Quantity,Description,UnitPrice,TotalPrice) VALUES(@ReqID,@Quantity,@Description,@UnitPrice,@TotalPrice)")
sqlcon.Close()
Last edited by a moderator: