Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2006, 07:55 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem getting updating Database from Datagrid

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?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem updating data from a datagrid jazzydonald Visual Basic 2005 Basics 0 October 16th, 2007 06:16 AM
Problem updating a DataGrid RichardP ASP.NET 1.0 and 1.1 Professional 3 February 28th, 2006 11:42 AM
problem updating using datagrid bananaking ASP.NET 1.0 and 1.1 Basics 7 May 13th, 2005 07:32 AM
problem in updating datagrid noor ASP.NET 1.0 and 1.1 Basics 1 April 26th, 2005 03:10 AM
updating database problem nazra Classic ASP Databases 10 July 25th, 2003 08:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.