System.Windows.Forms.TextBox is showing in the database.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msdhh
    New Member
    • Nov 2012
    • 8

    #1

    System.Windows.Forms.TextBox is showing in the database.

    Hi there, Im having a problem in my sql database,
    when i enter data in the textbox called "Name" and then i save it.
    it shows in the database like this:-

    System.Windows. Forms.TextBox, Text: Bob

    How can I get rid of this

    your help is greatly appreciated
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    And you need to post the code that you're using to create/save the record. Please remember to format posted code using the <CODE/> button in the toolbar.

    Comment

    • msdhh
      New Member
      • Nov 2012
      • 8

      #3
      Here is the code source

      I appreciate your quick response,
      here is the code im using to insert the values
      Code:
      private void Save_Click(object sender, EventArgs e)
              {
                  try
                  {
                      sql = "insert into Registration values('" + txt_usrName + "','" + txt_pass + "','" + Txt_Name + "','" + Txt_email + "','" + txt_Rank + "')";
                      if (conn.State == ConnectionState.Closed)
                      {
                          conn.Open();
                      }
                      cmd.CommandText = sql;
                      cmd.ExecuteNonQuery();
                      MessageBox.Show("You have successfully registered");
                  }
                  catch (Exception exe)
                  {
                      MessageBox.Show(exe.Message);
                  }
                  finally
                  {
                      if (conn.State == ConnectionState.Open)
                      {
                          conn.Close();
                      }
                  }
      
              }

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        You need to change this line:
        Code:
        sql = "insert into Registration values('" + txt_usrName + "','" + txt_pass + "','" + Txt_Name + "','" + Txt_email + "','" + txt_Rank + "')";
        to this:

        Code:
        sql = "insert into Registration values('" + txt_usrName.Text + "','" + txt_pass.Text + "','" + Txt_Name.Text + "','" + Txt_email.Text + "','" + txt_Rank.Text + "')";
        To get the value from the various TextBox controls you need to reference it's Text Property

        Comment

        • msdhh
          New Member
          • Nov 2012
          • 8

          #5
          thanks alot, it works :)

          Comment

          Working...