Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to insert data into a table in database using textbox
Posted
Comments
BELGIUMsky 20-Mar-14 6:15am    
What do you mean with data?
Is it just some text?

What database do you use?
What connection do you want to use? for example linq to sql or entity framework, ... .
Member 10464250 20-Mar-14 6:29am    
i want to send text into a table in sql database

1 solution

That's a very general question, but...because if you get it wrong you open yourself up to SQL Injection, which can damage or destroy your database, I'll answer it:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumnName) VALUES (@MYDATA)", con))
        {
        com.Parameters.AddWithValue("@MYDATA", myTextBox.Text);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 

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