locked
storing data RRS feed

  • Question

  • storing data from textbox to sql table .... can anyone provide me with a c# code for it
    • Moved by Bob BeaucheminEditor Tuesday, December 22, 2009 5:22 AM Moved to a more appropriate group (From:.NET Framework inside SQL Server)
    Saturday, December 12, 2009 5:18 AM

Answers

  • See http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx for examples of how to build and execute a parameterized SQL command.  As Gnanasekar Babu mentioned, you can do this as in your event handing code.  But you should never build a SQL statement string by concatenating user input as in the example posted.
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Marked as answer by KJian_ Monday, December 21, 2009 11:51 AM
    Monday, December 14, 2009 1:48 PM

All replies

  • Hi,

    Try the sample below

    Note : 1. Write the code in your Command button click
    2. Replace the connection string with your connection string

    string sInsertSQL = "";
    SqlConnection oSQLConn;
    oSQLConn = new SqlConnection("server=INDBSRV04\\DEV2;uid=pims;pwd=pims32;database=GOSH1871003");
    oSQLConn.Open();

    sInsertSQL = sInsertSQL + "INSERT INTO audit_failure (";
    sInsertSQL = sInsertSQL + " data)";
    sInsertSQL = sInsertSQL + " values (";
    sInsertSQL = sInsertSQL + "'" + Textbox1.text + "'";
    sInsertSQL = sInsertSQL + ")" ;

    SqlCommand oCmd = new SqlCommand(sInsertSQL, oSQLConn);
    oCmd.ExecuteNonQuery();
    oSQLConn.Close();
    oCmd.Dispose();

    Thanks,


    Gnanasekar Babu Note: Please click on the vote button if the answer helps you
    Monday, December 14, 2009 5:53 AM
  • See http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx for examples of how to build and execute a parameterized SQL command.  As Gnanasekar Babu mentioned, you can do this as in your event handing code.  But you should never build a SQL statement string by concatenating user input as in the example posted.
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Marked as answer by KJian_ Monday, December 21, 2009 11:51 AM
    Monday, December 14, 2009 1:48 PM