I have written a module which displays an editable DataGrid, DgSTDPD, but when I try to update the database, nothing seems to happen. My update code is:-
Private Sub BtnWrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnWrite.Click
' this sub routine saves the DataGrid changes to the Database then writes the extract record to disc
Dim objConnection = New OleDb.OleDbConnection(strConn)
'Dim strSelect As String
'strSelect = "select demand_date, demand_no, spc, dmc, nc, iin, demand_qty, locat, task_no, rdd, dmd_type from due_in where despatch_ind = 2 and dip = 'PSTO Devonport' and tsn = 391"
strSelect = "exec dbo.USp_STDPE_Select_DIP '" & strDIP & "','" & LblSeqNo.Text & "'"
Dim objCommandBuilder As OleDb.OleDbCommandBuilder
Dim cmdUpdate As New SqlClient.SqlCommand
Dim cmdSelect As New SqlClient.SqlCommand
Dim prm As SqlClient.SqlParameter
Dim mda As New SqlClient.SqlDataAdapter
cmdSelect = strConn2.CreateCommand
cmdSelect.CommandText = strSelect
mda.SelectCommand = cmdSelect
cmdUpdate = strConn2.CreateCommand
' it seems to want a select command at this stage so here it is
Dim SelectSTDPE As OleDb.OleDbCommand = New OleDb.OleDbCommand("USp_STDPE_Select_DIP", objConnection)
SelectSTDPE.CommandText = strSelect
Dim ParamDIP As OleDb.OleDbParameter = SelectSTDPE.Parameters.Add("@ParamDipname", OleDb.OleDbType.VarChar, 20)
Dim ParamSeqNo As OleDb.OleDbParameter = SelectSTDPE.Parameters.Add("@ParamSeqNo", OleDb.OleDbType.Integer, 4)
ParamDIP.Value = strDIP
ParamSeqNo.Value = CInt(LblSeqNo.Text)
' now I declare my update command. Only the Qty column can be updated
Dim UpdateSTDPE As OleDb.OleDbCommand = New OleDb.OleDbCommand("exec USp_STDPD_Update", objConnection)
prm = cmdUpdate.Parameters.Add("@paramDMDate", SqlDbType.NVarChar, 6, "demand_date")
prm = cmdUpdate.Parameters.Add("@paramDSN", SqlDbType.NVarChar, 4, "demand_no")
prm = cmdUpdate.Parameters.Add("@ParamQty", SqlDbType.Int, 4, "demand_qty")
prm.SourceVersion = DataRowVersion.Original
'UpdateSTDPE.CommandText = "exec dbo.USp_STDPD_Update '" & LblDSN.Text.Substring(0, 6) & "','" & LblDSN.Text.Substring(6, 4) & "','" & LblNewAmount.Text & "'"
UpdateSTDPE.CommandText = "update due_in set demand_qty = " & LblNewAmount.Text & " where demand_date = @ParamDate and demand_no = @ParamDSN"
Dim ParamDate As OleDb.OleDbParameter = UpdateSTDPE.Parameters.Add("@paramDMDate", OleDb.OleDbType.VarChar, 6)
Dim ParamDSN As OleDb.OleDbParameter = UpdateSTDPE.Parameters.Add("@paramDSN", OleDb.OleDbType.VarChar, 4)
Dim ParamQty As OleDb.OleDbParameter = UpdateSTDPE.Parameters.Add("@ParamQty", OleDb.OleDbType.Integer, 4)
'ParamDate.Value = LblDSN.Text.Substring(0, 6)
'ParamDSN.Value = LblDSN.Text.Substring(6, 4)
'ParamQty.Value = CInt(LblNewAmount.Text)
objCommandBuilder = New OleDb.OleDbCommandBuilder(objAdapter)
'objAdapter.SelectCommand = SelectSTDPE
objAdapter = New OleDb.OleDbDataAdapter(SelectSTDPE)
objAdapter.SelectCommand = SelectSTDPE
mda.UpdateCommand = cmdUpdate
'objAdapter.UpdateCommand = UpdateSTDPE
'objAdapter.Fill(DataSet1, "due_in")
mda.Fill(DataSet1, "due_in")
' this should save the data but does not appear to!
'objAdapter.Update(DataSet1, "due_in")
mda.Update(DataSet1, "due_in")
'I need to add code to write the data to disc. This could be either
VB or an SQL procedure or
'even a crystal report.
'LblApprepLine.Text = "If you want to e-mail the file, please click 'Email'"
LblApprepLine.Text = "Update Params: " & UpdateSTDPE.CommandText
End Sub
Any ideas anyone?