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. update database

update database

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorialannouncement
9 Posts 4 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
    mylogics
    wrote on last edited by
    #1

    hii m trying to update the column ProductID of table Product.db i have written the following code on pageload but its giving error: syntax error in update statement.where m i wrong.plz guide. the code is:

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    String str2 = "Select PID From Product Where(ProductID='PID1')";
    OleDbCommand cmd = new OleDbCommand(str2, conn);
    conn.Open();
    string m = cmd.ExecuteScalar().ToString();
    m = "PID" + m;
    conn.Close();
    string str3 = "Update Product Set(ProductID='" + m + "')Where(ProductID='PID1')";
    cmd = new OleDbCommand(str3, conn);
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    populateddl1();
    populateddl2();
    }
    }

    C 1 Reply Last reply
    0
    • M mylogics

      hii m trying to update the column ProductID of table Product.db i have written the following code on pageload but its giving error: syntax error in update statement.where m i wrong.plz guide. the code is:

      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      String str2 = "Select PID From Product Where(ProductID='PID1')";
      OleDbCommand cmd = new OleDbCommand(str2, conn);
      conn.Open();
      string m = cmd.ExecuteScalar().ToString();
      m = "PID" + m;
      conn.Close();
      string str3 = "Update Product Set(ProductID='" + m + "')Where(ProductID='PID1')";
      cmd = new OleDbCommand(str3, conn);
      conn.Open();
      cmd.ExecuteNonQuery();
      conn.Close();
      populateddl1();
      populateddl2();
      }
      }

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

      Well, the brackets in your SQL are at a mininum, superfluous. Why would you change all product IDs from a known value to the new one ? This code is an utter disaster, but I think it should work. However, I don't think this is what's blowing up. Are you sure this is the issue, because ASP.NET will only identify an 'update statement', if you try to use one of it's nasty, SQL holding controls that tries to update things for you. I think you've got the code there to use an updating control, and not the code in that control to do the update as it expects.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      M 1 Reply Last reply
      0
      • C Christian Graus

        Well, the brackets in your SQL are at a mininum, superfluous. Why would you change all product IDs from a known value to the new one ? This code is an utter disaster, but I think it should work. However, I don't think this is what's blowing up. Are you sure this is the issue, because ASP.NET will only identify an 'update statement', if you try to use one of it's nasty, SQL holding controls that tries to update things for you. I think you've got the code there to use an updating control, and not the code in that control to do the update as it expects.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        M Offline
        M Offline
        mylogics
        wrote on last edited by
        #3

        Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:

        string str1 = "Select MAX(PID) From Product";
        OleDbCommand cmd = new OleDbCommand(str1, conn);
        conn.Open();
        string max= cmd.ExecuteScalar().ToString();
        if (max == "")
        {
        max = "PID" + 1;
        }
        else
        {
        int i= Convert.ToInt32(max) + 1;
        string s1=Convert.ToString(i);
        max = "PID" + s1;
        }
        conn.Close();
        string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
        cmd = new OleDbCommand(str, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        str = "Select * From Product";
        cmd = new OleDbCommand(str, conn);
        OleDbDataReader dr1 = null;
        conn.Open();
        dr1 = cmd.ExecuteReader();
        DropDownList2.DataSource = dr1;
        DropDownList2.DataTextField = "ProductID";
        DropDownList2.DataValueField = "ProductID";
        DropDownList2.DataBind();
        conn.Close();

        so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.

        C C 2 Replies Last reply
        0
        • M mylogics

          Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:

          string str1 = "Select MAX(PID) From Product";
          OleDbCommand cmd = new OleDbCommand(str1, conn);
          conn.Open();
          string max= cmd.ExecuteScalar().ToString();
          if (max == "")
          {
          max = "PID" + 1;
          }
          else
          {
          int i= Convert.ToInt32(max) + 1;
          string s1=Convert.ToString(i);
          max = "PID" + s1;
          }
          conn.Close();
          string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
          cmd = new OleDbCommand(str, conn);
          conn.Open();
          cmd.ExecuteNonQuery();
          conn.Close();
          str = "Select * From Product";
          cmd = new OleDbCommand(str, conn);
          OleDbDataReader dr1 = null;
          conn.Open();
          dr1 = cmd.ExecuteReader();
          DropDownList2.DataSource = dr1;
          DropDownList2.DataTextField = "ProductID";
          DropDownList2.DataValueField = "ProductID";
          DropDownList2.DataBind();
          conn.Close();

          so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.

          C Offline
          C Offline
          Coding C
          wrote on last edited by
          #4

          Why you are repeating the post?? This should be your answer http://www.codeproject.com/Messages/3179523/access.aspx

          Coding C# ExciteTemplate

          M 1 Reply Last reply
          0
          • C Coding C

            Why you are repeating the post?? This should be your answer http://www.codeproject.com/Messages/3179523/access.aspx

            Coding C# ExciteTemplate

            M Offline
            M Offline
            mylogics
            wrote on last edited by
            #5

            m not insertin PID in Product table but m inserting ProductID value and it is necessary as it is primary key and cannot be null.

            C 1 Reply Last reply
            0
            • M mylogics

              Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:

              string str1 = "Select MAX(PID) From Product";
              OleDbCommand cmd = new OleDbCommand(str1, conn);
              conn.Open();
              string max= cmd.ExecuteScalar().ToString();
              if (max == "")
              {
              max = "PID" + 1;
              }
              else
              {
              int i= Convert.ToInt32(max) + 1;
              string s1=Convert.ToString(i);
              max = "PID" + s1;
              }
              conn.Close();
              string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
              cmd = new OleDbCommand(str, conn);
              conn.Open();
              cmd.ExecuteNonQuery();
              conn.Close();
              str = "Select * From Product";
              cmd = new OleDbCommand(str, conn);
              OleDbDataReader dr1 = null;
              conn.Open();
              dr1 = cmd.ExecuteReader();
              DropDownList2.DataSource = dr1;
              DropDownList2.DataTextField = "ProductID";
              DropDownList2.DataValueField = "ProductID";
              DropDownList2.DataBind();
              conn.Close();

              so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.

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

              Well, this code is excrable. Why would you assume that any postback is a new row ? Why would you not do all your code for an insertion inside your event ? Why would you not have a data layer ? Everything about this code is terrible. You should buy a book on ASP.NET and one on ADO.NET, and read them before writing any code. I assume no-one is paying for this code, if they are, you are a liar and a thief.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              G 1 Reply Last reply
              0
              • M mylogics

                m not insertin PID in Product table but m inserting ProductID value and it is necessary as it is primary key and cannot be null.

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

                If it's the primary key, why not make it an identity ? Either way, why not write a data layer, or at least write code to a semi professional standard ?

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                1 Reply Last reply
                0
                • C Christian Graus

                  Well, this code is excrable. Why would you assume that any postback is a new row ? Why would you not do all your code for an insertion inside your event ? Why would you not have a data layer ? Everything about this code is terrible. You should buy a book on ASP.NET and one on ADO.NET, and read them before writing any code. I assume no-one is paying for this code, if they are, you are a liar and a thief.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  G Offline
                  G Offline
                  Greg Chelstowski
                  wrote on last edited by
                  #8

                  Christian Graus wrote:

                  I assume no-one is paying for this code, if they are, you are a liar and a thief.

                  Depends on how much they pay for it Christian ;>

                  var question = (_2b || !(_2b));

                  C 1 Reply Last reply
                  0
                  • G Greg Chelstowski

                    Christian Graus wrote:

                    I assume no-one is paying for this code, if they are, you are a liar and a thief.

                    Depends on how much they pay for it Christian ;>

                    var question = (_2b || !(_2b));

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

                    Well, I am sure they know their website would cost $12000 to write in the US, and believe that the $50 they are paying this guy will get the same result. They probably deserve each other.

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    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