Click here to Skip to main content
15,891,855 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to have all the entered label to be display in label.

What I have tried:

SqlConnection con   = new SqlConnection(@"Data Source = My-pc\Sqlexpress; Integrated Security = SSPI; user = Sa; Password = 
            SqlCommand cmd = new SqlCommand("Insert Into EnterMessage (Message) Values ('" + lblEnterMessage.Text + "', '" + txtMessage.Text + "','");
            con.Open();
            cmd.Parameters.AddWithValue("EnterMessage", txtMessage.Text);
            cmd.ExecuteNonQuery();
            SqlDataAdapter sda = new SqlDataAdapter();
            SqlDataReader reader = cmd.ExecuteReader();
            con.Close();
Posted
Updated 18-Dec-17 6:54am
v2
Comments

If you're asking how to insert multiple textbox entries, you have to insert them one at a time. SQL doesn't understand that the comma you put in there is another entry to insert into it's own record.

Oh, and using the SA account is a really bad idea. Thanks for the password too.

That account gives the application access to do ANYTHING to the database, even destroy it. You might want to Google for "SQL Injection Attack" to find out why what you're doing is so bad and then Google for "C# parameterize queries" to find out what to do about it.
 
Share this answer
 
SqlConnection con   = new SqlConnection(@"Data Source = My-pc\Sqlexpress; Integrated Security = SSPI; user = Sa; Password = 
            SqlCommand cmd = new SqlCommand("Insert Into EnterMessage (Message) Values ('"  + txtMessage.Text + "'");
            con.Open();
           
            cmd.ExecuteNonQuery();
            
            con.Close();
 
Share this answer
 
Comments
Richard Deeming 18-Dec-17 13:38pm    
You have copied the SQL Injection[^] vulnerability from the question.

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

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