Click here to Skip to main content
15,890,982 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how does i store the values in database
Posted

C#
System.SQL.SqlClient.SqlConnection con = new System.SQL.SqlClient.SqlConnection(strConnect)
con.Open();
System.SQL.SqlClient.SqlCommand cmd = new System.SQL.SqlClient.SqlCommand("INSERT INTO myTable (column1, column2) VALUES ('col1Value', 'col2val')", con)
cmd.ExecuteNonQuery();
 
Share this answer
 
 
Share this answer
 
Comments
NeptuneHACK! 21-Jan-12 6:50am    
simply awesome
Try:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
        {
        com.Parameters.AddWithValue("@C1", myValueForColumn1);
        com.Parameters.AddWithValue("@C2", myValueForColumn2);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
koolprasad2003 21-Jan-12 3:37am    
Nice and Simple way, OriginalGriff. +5
Prashant Srivastava LKO 21-Jan-12 3:48am    
Sir,Nice answer my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900