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 March 31st, 2006, 08:51 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with update database in datagrid

I face a problem in update database while using datagrid. When i press the Edit button, textbox will display and let me edit the text inside the textbox, but when i press update button i can't update the data at the database. Below is my coding, can someone help me? Thanks.

Sub DataGrid1_EditCommand(sender As Object, e As DataGridCommandEventArgs)
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Sub DataGrid1_UpdateCommand(sender As Object, e As DataGridCommandEventArgs)
Dim id As String = CType(e.Item.Cells(0).Controls(0), TextBox).Text
Dim str As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim myConnection As New SqlConnection (ConfigurationSettings.AppSettings("ConnectionStri ng"))
Dim cmdStr As String = "update Student set stuName=@stuName where stuId='"+id+"'"
Dim cmd As New SqlCommand (cmdStr, myConnection)
cmd.Parameters.Add("@stuName", SqlDbType.VarChar, 50).Value = str
myConnection.Open()
cmd.ExecuteNonQuery()
myConnection.Close()
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

 
Old March 31st, 2006, 10:04 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

what is the error you are getting?

"The one language all programmers understand is profanity."
 
Old March 31st, 2006, 12:40 PM
RGB RGB is offline
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you have an OnUpdateCommand in your HTML view for your grid. Something like OnupdateCommand="DataGrid1_EditCommand"

What Do You Mean It Does Not Work
 
Old April 1st, 2006, 12:07 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dparsons, that is no error on my program. just when i click update button at datagrid there, my data at database did not update, the data still same with the old data.

 
Old April 1st, 2006, 12:10 AM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

RGB, the "OnUpdateCommand="DataGrid1_UpdateCommand"" already in my html code there.

I cant update my data. when i press update button at datagrid, my data still maintain with the old data.





Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrid, innertext, javascript, database update vsr ASP.NET 1.0 and 1.1 Professional 1 November 6th, 2007 05:54 PM
Update Access Database with datagrid jeff_M General .NET 2 May 19th, 2007 10:44 AM
Update Problem In DataGrid prasanta2expert ASP.NET 1.0 and 1.1 Basics 7 January 9th, 2007 07:36 AM
update DataBase from DataGrid AnwarSadique C# 1 July 26th, 2006 09:03 AM
Datagrid update, dropdownlist database insertion herman ASP.NET 1.0 and 1.1 Professional 2 October 11th, 2003 01:31 AM





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