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. query

query

Scheduled Pinned Locked Moved ASP.NET
databasehelp
10 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

    hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:

    protected void Button2_Click(object sender, EventArgs e)
    {
    OleDbDataReader dr = null;
    string str = "Select Count(Specification)From ProductSpecification";
    OleDbCommand cmd = new OleDbCommand(str, conn);
    conn.Open();
    string Count = cmd.ExecuteScalar().ToString();
    int count = Convert.ToInt32(Count);
    conn.Close();
    str = "Select * From ProductSpecification";
    cmd = new OleDbCommand(str, conn);
    conn.Open();
    // dr = cmd.ExecuteReader();
    //DataTable dt = new DataTable();
    // dt.Load(dr);

        for (int i = 1; i <= count; i++)
        {
            txt = new TextBox\[count\]; 
            //string s=dr\["Specification"\].ToString();
            //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID);
            ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString());
            txt\[i\] = new TextBox(); 
            txt\[i\].ID = "txt" + i.ToString();
            string s1 = txt\[i\].Text;
            string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')";
            cmd = new OleDbCommand(s2, conn);
            cmd.ExecuteNonQuery();
           
        }
        conn.Close();
    }
    

    but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.

    S C 2 Replies Last reply
    0
    • M mylogics

      hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:

      protected void Button2_Click(object sender, EventArgs e)
      {
      OleDbDataReader dr = null;
      string str = "Select Count(Specification)From ProductSpecification";
      OleDbCommand cmd = new OleDbCommand(str, conn);
      conn.Open();
      string Count = cmd.ExecuteScalar().ToString();
      int count = Convert.ToInt32(Count);
      conn.Close();
      str = "Select * From ProductSpecification";
      cmd = new OleDbCommand(str, conn);
      conn.Open();
      // dr = cmd.ExecuteReader();
      //DataTable dt = new DataTable();
      // dt.Load(dr);

          for (int i = 1; i <= count; i++)
          {
              txt = new TextBox\[count\]; 
              //string s=dr\["Specification"\].ToString();
              //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID);
              ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString());
              txt\[i\] = new TextBox(); 
              txt\[i\].ID = "txt" + i.ToString();
              string s1 = txt\[i\].Text;
              string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')";
              cmd = new OleDbCommand(s2, conn);
              cmd.ExecuteNonQuery();
             
          }
          conn.Close();
      }
      

      but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.

      S Offline
      S Offline
      Suresh Suthar
      wrote on last edited by
      #2

      mylogics wrote:

      txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;

      Use this

      txt = new TextBox();
      txt= Page.FindControl("txt" & i.ToString);
      string s1= txt.Text

      Be an Eagle, Sky is Yours.

      M R 2 Replies Last reply
      0
      • S Suresh Suthar

        mylogics wrote:

        txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;

        Use this

        txt = new TextBox();
        txt= Page.FindControl("txt" & i.ToString);
        string s1= txt.Text

        Be an Eagle, Sky is Yours.

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

        hiii now i have changed my code to:

        protected void Button2_Click(object sender, EventArgs e)
        {
        OleDbDataReader dr = null;
        string str = "Select Count(Specification)From ProductSpecification";
        OleDbCommand cmd = new OleDbCommand(str, conn);
        conn.Open();
        string Count = cmd.ExecuteScalar().ToString();
        int count = Convert.ToInt32(Count);
        conn.Close();

            for (int i = 0; i <= Convert.ToInt32(Count) - 1; i++)
            {
                TextBox txtCtrl = (TextBox)Panel2.FindControl("txt" + (i + 1));
                Label lblctrl = (Label)Panel2.FindControl("lbl" + (i + 1));
                if (txtCtrl != null) 
                {
                    string s = txtCtrl.Text;
                    string s2 = lblctrl.Text;
                    string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";
                    cmd = new OleDbCommand(s1, conn);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                    //TextBox1.Text = TextBox1.Text + "," + txtCtrl.Text;
                }
            }
        
        }
        

        but it is givin error: Syntax error in UPDATE statement. plz help...

        S 1 Reply Last reply
        0
        • S Suresh Suthar

          mylogics wrote:

          txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;

          Use this

          txt = new TextBox();
          txt= Page.FindControl("txt" & i.ToString);
          string s1= txt.Text

          Be an Eagle, Sky is Yours.

          R Offline
          R Offline
          rummer
          wrote on last edited by
          #4

          Hi sir i want to say my code is for text but i want 2 ask u how we use this code for date format.

          S C 2 Replies Last reply
          0
          • M mylogics

            hiii now i have changed my code to:

            protected void Button2_Click(object sender, EventArgs e)
            {
            OleDbDataReader dr = null;
            string str = "Select Count(Specification)From ProductSpecification";
            OleDbCommand cmd = new OleDbCommand(str, conn);
            conn.Open();
            string Count = cmd.ExecuteScalar().ToString();
            int count = Convert.ToInt32(Count);
            conn.Close();

                for (int i = 0; i <= Convert.ToInt32(Count) - 1; i++)
                {
                    TextBox txtCtrl = (TextBox)Panel2.FindControl("txt" + (i + 1));
                    Label lblctrl = (Label)Panel2.FindControl("lbl" + (i + 1));
                    if (txtCtrl != null) 
                    {
                        string s = txtCtrl.Text;
                        string s2 = lblctrl.Text;
                        string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";
                        cmd = new OleDbCommand(s1, conn);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        conn.Close();
                        //TextBox1.Text = TextBox1.Text + "," + txtCtrl.Text;
                    }
                }
            
            }
            

            but it is givin error: Syntax error in UPDATE statement. plz help...

            S Offline
            S Offline
            Suresh Suthar
            wrote on last edited by
            #5

            mylogics wrote:

            string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";

            Dear Friend Please write you query with space between where cluase and single quote

            string s1 = "Update ProductSpecification Set Value='"+s+"' Where Specification='"+s2+"'";

            Be an Eagle, Sky is Yours.

            M 1 Reply Last reply
            0
            • R rummer

              Hi sir i want to say my code is for text but i want 2 ask u how we use this code for date format.

              S Offline
              S Offline
              Suresh Suthar
              wrote on last edited by
              #6

              Plz explain. put you code here...

              Be an Eagle, Sky is Yours.

              1 Reply Last reply
              0
              • S Suresh Suthar

                mylogics wrote:

                string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";

                Dear Friend Please write you query with space between where cluase and single quote

                string s1 = "Update ProductSpecification Set Value='"+s+"' Where Specification='"+s2+"'";

                Be an Eagle, Sky is Yours.

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

                i have written the query as u said but still givin same error...

                S 1 Reply Last reply
                0
                • M mylogics

                  i have written the query as u said but still givin same error...

                  S Offline
                  S Offline
                  Suresh Suthar
                  wrote on last edited by
                  #8

                  If you passing text with single qoute like D'Souza then replace single quoute with ''.

                  Be an Eagle, Sky is Yours.

                  1 Reply Last reply
                  0
                  • M mylogics

                    hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:

                    protected void Button2_Click(object sender, EventArgs e)
                    {
                    OleDbDataReader dr = null;
                    string str = "Select Count(Specification)From ProductSpecification";
                    OleDbCommand cmd = new OleDbCommand(str, conn);
                    conn.Open();
                    string Count = cmd.ExecuteScalar().ToString();
                    int count = Convert.ToInt32(Count);
                    conn.Close();
                    str = "Select * From ProductSpecification";
                    cmd = new OleDbCommand(str, conn);
                    conn.Open();
                    // dr = cmd.ExecuteReader();
                    //DataTable dt = new DataTable();
                    // dt.Load(dr);

                        for (int i = 1; i <= count; i++)
                        {
                            txt = new TextBox\[count\]; 
                            //string s=dr\["Specification"\].ToString();
                            //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID);
                            ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString());
                            txt\[i\] = new TextBox(); 
                            txt\[i\].ID = "txt" + i.ToString();
                            string s1 = txt\[i\].Text;
                            string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')";
                            cmd = new OleDbCommand(s2, conn);
                            cmd.ExecuteNonQuery();
                           
                        }
                        conn.Close();
                    }
                    

                    but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.

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

                    Well, this has to be the most ridiculous code I've seen in a long time.

                    mylogics wrote:

                    txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text; string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')";

                    Well, why would you expect s1 to be anything, but an empty string ? What on earth are you expecting here ?

                    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
                    • R rummer

                      Hi sir i want to say my code is for text but i want 2 ask u how we use this code for date format.

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

                      your code is a disaster from start to finish. It has zero chance of working. You should rethink it, and perhaps do some study, so you have a basic idea of what you are doing. you should also read up on paramaterised queries, once your code is not totally useless, it will become totally insecure, due to SQL injection attacks. Once you fix that, it will also work for dates, as a side benefit.

                      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