Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datagrid

Datagrid

Scheduled Pinned Locked Moved ASP.NET
databasecssdesignsaleshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toanthinh
    wrote on last edited by
    #1

    How to update or delete direct from Grid to Database?I tried my best but fail.Please help me.I have enclosed my code. Please modify Private Sub Grid_Customer_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Luoi_khach_hang.UpdateCommand Dim Name1 As TextBox = e.Item.Cells(0).Controls(0) Dim Name2 As TextBox = e.Item.Cells(1).Controls(0) Dim Sex As CheckBox = e.Item.FindControl("Phai") Dim Custom_Code As Integer = Luoi_khach_hang.DataKeys(e.Item.ItemIndex) Dim SQL As String = "UPDATE khach_hang SET ho_khach_hang='" & Name1.Text & "',ten_khach_hang='" & name2.Text & "',gioi_tinh=" & Sex.Checked & " where mkh=" & Customer_Code Dim Connect As OleDb.OleDbConnection = Bang_khach_hang.Connect Connect.Open() Dim cmd As New OleDb.OleDbCommand(sql, Connect) Try cmd.ExecuteNonQuery() Catch ex As Exception End Try Connect.Close() Grid_Customer.EditItemIndex = -1 Doc_danh_sach_khach_hang() Lien_ket_du_lieu() End Sub

    P T 2 Replies Last reply
    0
    • T toanthinh

      How to update or delete direct from Grid to Database?I tried my best but fail.Please help me.I have enclosed my code. Please modify Private Sub Grid_Customer_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Luoi_khach_hang.UpdateCommand Dim Name1 As TextBox = e.Item.Cells(0).Controls(0) Dim Name2 As TextBox = e.Item.Cells(1).Controls(0) Dim Sex As CheckBox = e.Item.FindControl("Phai") Dim Custom_Code As Integer = Luoi_khach_hang.DataKeys(e.Item.ItemIndex) Dim SQL As String = "UPDATE khach_hang SET ho_khach_hang='" & Name1.Text & "',ten_khach_hang='" & name2.Text & "',gioi_tinh=" & Sex.Checked & " where mkh=" & Customer_Code Dim Connect As OleDb.OleDbConnection = Bang_khach_hang.Connect Connect.Open() Dim cmd As New OleDb.OleDbCommand(sql, Connect) Try cmd.ExecuteNonQuery() Catch ex As Exception End Try Connect.Close() Grid_Customer.EditItemIndex = -1 Doc_danh_sach_khach_hang() Lien_ket_du_lieu() End Sub

      P Offline
      P Offline
      postmaster programmingknowledge com
      wrote on last edited by
      #2

      Try this example http://www.programmingknowledge.com/simpleDataGrid.aspx[^]

      1 Reply Last reply
      0
      • T toanthinh

        How to update or delete direct from Grid to Database?I tried my best but fail.Please help me.I have enclosed my code. Please modify Private Sub Grid_Customer_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Luoi_khach_hang.UpdateCommand Dim Name1 As TextBox = e.Item.Cells(0).Controls(0) Dim Name2 As TextBox = e.Item.Cells(1).Controls(0) Dim Sex As CheckBox = e.Item.FindControl("Phai") Dim Custom_Code As Integer = Luoi_khach_hang.DataKeys(e.Item.ItemIndex) Dim SQL As String = "UPDATE khach_hang SET ho_khach_hang='" & Name1.Text & "',ten_khach_hang='" & name2.Text & "',gioi_tinh=" & Sex.Checked & " where mkh=" & Customer_Code Dim Connect As OleDb.OleDbConnection = Bang_khach_hang.Connect Connect.Open() Dim cmd As New OleDb.OleDbCommand(sql, Connect) Try cmd.ExecuteNonQuery() Catch ex As Exception End Try Connect.Close() Grid_Customer.EditItemIndex = -1 Doc_danh_sach_khach_hang() Lien_ket_du_lieu() End Sub

        T Offline
        T Offline
        toanthinh
        wrote on last edited by
        #3

        I see you use Datareader.But I don't use it.I am using Datatable.Please give code in Datatable.Anyway I would be grateful.Thanks very very very much much much

        T 1 Reply Last reply
        0
        • T toanthinh

          I see you use Datareader.But I don't use it.I am using Datatable.Please give code in Datatable.Anyway I would be grateful.Thanks very very very much much much

          T Offline
          T Offline
          toanthinh
          wrote on last edited by
          #4

          I forget that . My application alerts the strange error is that: operation must use an updateable query. But my query is very exactly

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups