Link Button to sql table and store value entered in text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pratimapaudel
    New Member
    • Jul 2007
    • 24

    Link Button to sql table and store value entered in text box

    I have one text box and submit button in one asp.net page. When users enter their email address in textbox and click submit button, i want to store that email address which comes from text box in sql server table. Sql database name is 'uprod'. Prod database has table named unsuscribe with column name email.
    Can anyone help me? I appreciate your answer.

    Thanks,
    Pinky
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    For storing the value of textbox into db table you can make use of the one of the following methods :

    1> Write the sql statement into .Net code in order to insert the value of textbox into db table.

    2>OR Write stored procedure for inserting the value into db table and call the stored procedure from your .Net code.

    3> In order execute the stored procedure or sql query,set the appropriate properties of the command object.

    4> Call the ExecuteNonQuery () method of the command object in order to run the stored procedure and sql query.

    Comment

    • orked
      New Member
      • Jan 2009
      • 49

      #3
      hi
      this code i use it for the same aim
      Code:
        SqlConnection dbCon = new SqlConnection();
              dbCon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB.mdf;Integrated Security=True;User Instance=True";
              dbCon.Open();
              SqlCommand sqlcom = new SqlCommand();
              sqlcom.Connection = dbCon;
              sqlcom.CommandType = CommandType.Text;
      sqlcom.CommandText = "insert into applicant(EmailAddress) values('" + EmailTextBox.Text + "');
       SqlDataReader rdrData;
      
              rdrData = sqlcom.ExecuteReader();
      
              
              GridView1.DataBind();
              dbCon.Close();
              Label13.Visible = false;
              Label14.Visible = false;
              OutputLabel.Visible = true;
      you must change something in code in order to suitable for your application
      Regards
      orked
      Last edited by Frinavale; Feb 10 '09, 03:15 PM. Reason: added [code] tags

      Comment

      • pratimapaudel
        New Member
        • Jul 2007
        • 24

        #4
        Hi Orked
        Thank you very much for your code. I am going to try it now. Thank you very much again. I will let you know the result of this.
        Thanks

        Comment

        • pratimapaudel
          New Member
          • Jul 2007
          • 24

          #5
          Shweta,
          Thanks for your ideas.




          Originally posted by shweta123
          Hi,

          For storing the value of textbox into db table you can make use of the one of the following methods :

          1> Write the sql statement into .Net code in order to insert the value of textbox into db table.

          2>OR Write stored procedure for inserting the value into db table and call the stored procedure from your .Net code.

          3> In order execute the stored procedure or sql query,set the appropriate properties of the command object.

          4> Call the ExecuteNonQuery () method of the command object in order to run the stored procedure and sql query.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Hi Pratimapaudel,

            Please take a look at the article on how to use a database in your program and if you aren't using MSSql as your database, check out how to use a database in your program part II.

            -Frinny

            Comment

            Working...