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
  1. Home
  2. Web Development
  3. ASP.NET
  4. update database from datagrid

update database from datagrid

Scheduled Pinned Locked Moved ASP.NET
helpdatabaseannouncement
2 Posts 1 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.
  • M Offline
    M Offline
    matjame
    wrote on last edited by
    #1

    Hi guys.Im looking to update my database from my datagrid. When u click on edit, it gives you an option to update or cancel action, so I need to update the database after making the change.Prolem with this code is that it work for txt boxes not datagrid, but it shudnt be that different. My previous code is like this, so Im hoping sumone will assist me in doing so. Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged If IsNumeric(txtFirstName.Text) Then MsgBox("Please type your name in letters", MsgBoxStyle.Critical, "KNS System-Error") Exit Sub End If If IsNumeric(txtCity.Text) Then MsgBox("Please type your City in letters", MsgBoxStyle.Critical, "KNS System-Error") Exit Sub End If If Not IsNumeric(txtPostalCode.Text) Then MsgBox("Please type your PostalCode in numbers", MsgBoxStyle.Critical, "KNS-System-Error") Exit Sub End If If Not IsNumeric(txtCelnumber.Text) Then MsgBox("Please type your Cellphonenumber in numbers", MsgBoxStyle.Critical, "KNS-System-Error") Exit Sub End If da = New OleDbDataAdapter("Select * From Employees", cn) cb = New OleDbCommandBuilder(da) ds = New DataSet ds.Clear() da.Fill(ds, "Employees") dt = New DataTable dt = ds.Tables("Employees") Dim dr() As DataRow dr = dt.Select("EmpID = " & txtEmpID.Text & "") dr(0).BeginEdit() 'dr(0)("Client_ID") = txtClientID.Text dr(0)("EFirstName") = txtFirstName.Text dr(0)("ESurname") = txtSurname.Text dr(0)("EDepartment") = cboDept.SelectedItem dr(0)("EPassword") = txtPassword.Text dr(0)("EConfirmPassword") = txtConfirm.Text dr(0)("EPhonenumber") = mtxtPhoneNumber.Text dr(0)("ECelnumber") = txtCelnumber.Text dr(0)("EAddress") = txtAddress.Text dr(0)("ECity") = txtCity.Text dr(0)("EPostalcode") = txtPostalCode.Text dr(0).EndEdit() da.Update(ds, "Employees") MsgBox("Record Edited Successfully") Disabling() End Sub Problem is that this I did with text boxes.What Im looking for is updating directly from the datagrid.Thanx in advance

    kagiso

    M 1 Reply Last reply
    0
    • M matjame

      Hi guys.Im looking to update my database from my datagrid. When u click on edit, it gives you an option to update or cancel action, so I need to update the database after making the change.Prolem with this code is that it work for txt boxes not datagrid, but it shudnt be that different. My previous code is like this, so Im hoping sumone will assist me in doing so. Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged If IsNumeric(txtFirstName.Text) Then MsgBox("Please type your name in letters", MsgBoxStyle.Critical, "KNS System-Error") Exit Sub End If If IsNumeric(txtCity.Text) Then MsgBox("Please type your City in letters", MsgBoxStyle.Critical, "KNS System-Error") Exit Sub End If If Not IsNumeric(txtPostalCode.Text) Then MsgBox("Please type your PostalCode in numbers", MsgBoxStyle.Critical, "KNS-System-Error") Exit Sub End If If Not IsNumeric(txtCelnumber.Text) Then MsgBox("Please type your Cellphonenumber in numbers", MsgBoxStyle.Critical, "KNS-System-Error") Exit Sub End If da = New OleDbDataAdapter("Select * From Employees", cn) cb = New OleDbCommandBuilder(da) ds = New DataSet ds.Clear() da.Fill(ds, "Employees") dt = New DataTable dt = ds.Tables("Employees") Dim dr() As DataRow dr = dt.Select("EmpID = " & txtEmpID.Text & "") dr(0).BeginEdit() 'dr(0)("Client_ID") = txtClientID.Text dr(0)("EFirstName") = txtFirstName.Text dr(0)("ESurname") = txtSurname.Text dr(0)("EDepartment") = cboDept.SelectedItem dr(0)("EPassword") = txtPassword.Text dr(0)("EConfirmPassword") = txtConfirm.Text dr(0)("EPhonenumber") = mtxtPhoneNumber.Text dr(0)("ECelnumber") = txtCelnumber.Text dr(0)("EAddress") = txtAddress.Text dr(0)("ECity") = txtCity.Text dr(0)("EPostalcode") = txtPostalCode.Text dr(0).EndEdit() da.Update(ds, "Employees") MsgBox("Record Edited Successfully") Disabling() End Sub Problem is that this I did with text boxes.What Im looking for is updating directly from the datagrid.Thanx in advance

      kagiso

      M Offline
      M Offline
      matjame
      wrote on last edited by
      #2

      Guys, I found something but still I get errors. Code. Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated Dim cm As New OleDbCommand Dim con As New OleDbConnection Dim str1 As String = "Provider = Microsoft.Jet.oledb.4.0; Data source =C:\Documents and Settings\Kagisho.Mashiloane.ALFRGIS\My Documents\Visual Studio 2005\Projects\Search AL\TelephoneList.mdb" Dim str2 As String con = New OleDbConnection(str1) con.Open() str2 = "select * From Extensions" cm = New OleDbCommand(str2, con) Dim updateSQL As String = "UPDATE Extension SET Name = @Name, " & "Surname = @Surname, " & "Xtension = @Xtension" cm.Parameters.Clear() cm.Parameters.Add("@Name", Name) cm.Parameters.Add("@Surname", Surname) cm.Parameters.Add("@Xtension", Xtension) cm.ExecuteNonQuery() 'Next lblUpdatemessage.Text = "Update Successfull"

      kagiso

      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