Jump to content

update event in web form datagrid


Guest hooplife

Recommended Posts

Guest hooplife

help i'm looking to make update on web formdatagrid to my database, but seems i cant get the correct coding for the update event, even i had manage to make the datagrid into edit mode, please help me!!!it's urgent....here is my coding:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load'Put user code to initialize the page hereEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMe.OleDbConnection1.Open()DataSet11.Clear()Me.OleDbDataAdapter1.Fill(DataSet11)Me.OleDbConnection1.Close()DataGrid1.DataBind()End SubPrivate Sub DataGrid1_EditCommand(ByVal source As Object, _ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _Handles DataGrid1.EditCommandDataGrid1.EditItemIndex = e.Item.ItemIndexMe.OleDbDataAdapter1.Fill(DataSet11)DataGrid1.DataBind()End Sub******PROBLEM START HERE************************************Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _Handles DataGrid1.UpdateCommandMe.OleDbConnection1.Open() Dim txtname As TextBox Dim idd As String Dim namee As String Dim txtid As TextBox Dim intRowsAffected As Integer txtname = CType(e.Item.FindControl("Cusname"), TextBox) namee = txtname.Text txtid = CType(e.Item.FindControl("Cusid"), TextBox) idd = txtid.Text Me.OleDbUpdateCommand1.CommandText = "UPDATE cus SET Cusname = ? WHERE (Cusid = ?) AND (Age = ? OR ? IS NULL AND Age IS NULL) AN" & _ "D (Balance = ? OR ? IS NULL AND Balance IS NULL) AND (Contact = ? OR ? IS NULL A" & _ "ND Contact IS NULL) AND (Cusname = ? OR ? IS NULL AND Cusname IS NULL) AND (Icnu" & _ "m = ? OR ? IS NULL AND Icnum IS NULL) AND (Password = ? OR ? IS NULL AND Passwor" & _ "d IS NULL);" Me.OleDbUpdateCommand1.Parameters("Original_Cusid").Value = idd.ToString Me.OleDbUpdateCommand1.Parameters("Original_Cusname").Value = namee.ToString intRowsAffected = Me.OleDbUpdateCommand1.ExecuteNonQuery() DataGrid1.EditItemIndex = -1 Me.OleDbDataAdapter1.Fill(DataSet11) DataGrid1.DataBind() Me.OleDbConnection1.Close()End Sub*****************************************************************************Private Sub DataGrid1_CancelCommand(ByVal source As Object, _ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _Handles DataGrid1.CancelCommandDataGrid1.EditItemIndex = -1Me.OleDbDataAdapter1.Fill(DataSet11)DataGrid1.DataBind()End Sub

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...