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. General Programming
  3. C#
  4. updating access database in C#2005

updating access database in C#2005

Scheduled Pinned Locked Moved C#
csharpdatabasehelpannouncement
3 Posts 3 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.
  • C Offline
    C Offline
    csanda1
    wrote on last edited by
    #1

    Hi everyone Im using c# 2005 and I want to update my access database, it can insert fine and has no errors but just does not update Here's the code below string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; OleDbCommand command = new OleDbCommand(); string bhala = "Update Table1 Set CompanyName ='"+txtCompany.Text+"' where CompanyName = '" + txtCompany.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(bhala, datatryConn); //DataSet ds = new DataSet(); DataRow r = datatryds.Tables["Table1"].NewRow(); //r["CompanyName"] = txtCompany.Text; datatryds.Tables["Table1"].Rows.Find(r); r.BeginEdit(); r["CompanyName"] = txtCompany.Text; r.EndEdit(); if (datatryds.HasChanges()) { da.Update(datatryds, "Table1"); datatryds.AcceptChanges(); } OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(da); //da.Update(datatryds, "Table1"); //this.table1TableAdapter.Update(this.datatryds.Table1); datatryConn.Close(); MessageBox.Show("Updated successfully!"); Thank you any help is appreciated csanda

    E C 2 Replies Last reply
    0
    • C csanda1

      Hi everyone Im using c# 2005 and I want to update my access database, it can insert fine and has no errors but just does not update Here's the code below string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; OleDbCommand command = new OleDbCommand(); string bhala = "Update Table1 Set CompanyName ='"+txtCompany.Text+"' where CompanyName = '" + txtCompany.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(bhala, datatryConn); //DataSet ds = new DataSet(); DataRow r = datatryds.Tables["Table1"].NewRow(); //r["CompanyName"] = txtCompany.Text; datatryds.Tables["Table1"].Rows.Find(r); r.BeginEdit(); r["CompanyName"] = txtCompany.Text; r.EndEdit(); if (datatryds.HasChanges()) { da.Update(datatryds, "Table1"); datatryds.AcceptChanges(); } OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(da); //da.Update(datatryds, "Table1"); //this.table1TableAdapter.Update(this.datatryds.Table1); datatryConn.Close(); MessageBox.Show("Updated successfully!"); Thank you any help is appreciated csanda

      E Offline
      E Offline
      Ermak86
      wrote on last edited by
      #2

      "Update Table1 Set CompanyName ='"+txtCompany.Text+"' where CompanyName = '" + txtCompany.Text + "'"; I think this won't do anything because you set companyNames with string txtCompany.Text in rows where this name already is.

      1 Reply Last reply
      0
      • C csanda1

        Hi everyone Im using c# 2005 and I want to update my access database, it can insert fine and has no errors but just does not update Here's the code below string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; OleDbCommand command = new OleDbCommand(); string bhala = "Update Table1 Set CompanyName ='"+txtCompany.Text+"' where CompanyName = '" + txtCompany.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(bhala, datatryConn); //DataSet ds = new DataSet(); DataRow r = datatryds.Tables["Table1"].NewRow(); //r["CompanyName"] = txtCompany.Text; datatryds.Tables["Table1"].Rows.Find(r); r.BeginEdit(); r["CompanyName"] = txtCompany.Text; r.EndEdit(); if (datatryds.HasChanges()) { da.Update(datatryds, "Table1"); datatryds.AcceptChanges(); } OleDbCommandBuilder objCommandBuilder = new OleDbCommandBuilder(da); //da.Update(datatryds, "Table1"); //this.table1TableAdapter.Update(this.datatryds.Table1); datatryConn.Close(); MessageBox.Show("Updated successfully!"); Thank you any help is appreciated csanda

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        As someone else said, this can't work, you need the old name in order to find the right record to update, unless you have a unique Id ( definately a better idea ) to identify the one record you want to change. Your code is also insecure, you need to read up on SQL injection attacks.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        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