Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Re: Datagrid update problem...


Message #1 by "Steve Thomas" <sthomas@t...> on Mon, 13 Jan 2003 21:57:24
> Hi,
 >   I want to update datagrid data on click of update. I have written 
below 
c> ode...
=> ==========================================================
P> rivate Sub dgUser_UpdateCommand(ByVal source As Object, ByVal e As 
S> ystem.Web.UI.WebControls.DataGridCommandEventArgs) Handles 
d> gUser.UpdateCommand
 >        Dim txtLoginID As TextBox = e.Item.Cells(1).Controls(0)
 >        Dim txtCustID As TextBox = e.Item.Cells(2).Controls(0)
 >        Dim txtCustName As TextBox = e.Item.Cells(3).Controls(0)
 >        Dim strSql As String
 >        Dim objUser As New NexUserCls()
 >        
 >        'txtLoginID = e.Item.Cells(1).Controls(0)
 >        'txtCustID = e.Item.Cells(2).Controls(0)
 >        'txtCustName = e.Item.Cells(3).Controls(0)
 >        mintPK = dsUserList.Tables("UserList").Rows(e.Item.ItemIndex)
(> "intPK")

>         If objUser.fncUpdateUser(Trim(txtLoginID.Text), Trim
(> txtCustID.Text), Trim(txtCustName.Text), mintPK) = True Then
 >        End If
 >        dgUser.EditItemIndex = -1
 >        mintPK = 0
 >        subDisplayUsers()
 >    End Sub

> ===========================================================

> but the problem is it is not updating the data, because 
t> xtLoginID.Text.... is comming as old data(not modified data) even if i 
h> ave modified data.

> if anybody knows cause and solution for this mail me..
T> hankx in advance
R> amprasad
Message #2 by "Steve Thomas" <sthomas@t...> on Mon, 13 Jan 2003 21:58:08
Did you find a solution to this problem? I'm having the same problem.

Thanks
Message #3 by "Steve Thomas" <sthomas@t...> on Mon, 13 Jan 2003 22:31:45
The problem may be that you need to check for page.ispostback on the page 
load of the page...as in IF NOT PAGE.ISPOSTBACK THEN...do the page load 
code.
Message #4 by "Rich Lipscomb" <rlipscomb@h...> on Mon, 27 Jan 2003 05:58:59
I have a working datagrid which updates fine, but when I added a new date 
column in the datagrid and added two lines of code below to the update 
event I get the error: Exception Details: 
System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.

What is wrong with the two lines of marked code below?  Thanks.

sub MyDataGrid_Update(sender as object, e as DataGridCommandEventArgs)

dim myrow as integer = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
Dim sqlstr As String = "UPDATE calendar SET caldate = @caldate, event = 
@event, desc = @desc WHERE calID = " & myrow			
		
Cmd = New OleDbCommand(sqlstr, cn)

'these are the two new lines that must be causing the problem:
cmd.Parameters.Add(New OleDbParameter("@caldate",  OleDbType.Date))
Cmd.Parameters("@caldate").Value = CType(e.Item.FindControl("txtdate"), 
TextBox).Text   

cmd.Parameters.Add(New OleDbParameter("@event",  OleDbType.Varchar, 22))
Cmd.Parameters("@event").Value = CType(e.Item.FindControl("txtevent"), 
TextBox).Text
cmd.Parameters.Add(New OleDbParameter("@Desc", OleDbType.Varchar, 255))
Cmd.Parameters("@desc").Value = CType(e.Item.FindControl("txtDesc"), 
TextBox).Text


Cmd.Connection.Open()
Cmd.ExecuteNonQuery()
Cmd.Connection.Close()
MyDataGrid.edititemindex = -1
BindGrid("event")
end sub 

  Return to Index