0

How can I add in a table with a column of type string (in SQL Server) an string like "[email protected]" , I have problems with special character('@' in this case).Thanks

System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
                         "Data Source=BOGDAN-PC\\BOGDAN;Initial Catalog=ePlanning;Integrated Security=SSPI;Connect Timeout=10;TrustServerCertificate=True ");
                string[] id_dep = ddDepartament.SelectedItem.Text.Split('.');
                con.Open();



                string final = tbemailangajat.Text.

                string sqlstring = " Update angajati set nume='" + tbNumeangajat.Text + "' ,prenume= '" + tbPrenumeangajat.Text + "',email= '" + final + "',telefon= '" + tbTelefonAngajat.Text + "',id_functie= " + ddFunctieAngajat.SelectedItem.Text[0].ToString() + ",id_departament= " + ddDepartament.SelectedItem.Text[0].ToString() + " where id_angajat = " + int.Parse(tbID.Text) + ";";
                System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlstring, con);
                //  System.Data.SqlClient.SqlDataReader reader;
                comm.ExecuteNonQuery();
                con.Close();
8
  • 3
    What exactly is your problem? Commented Jul 11, 2012 at 17:02
  • post your C# code. and also Error Commented Jul 11, 2012 at 17:03
  • I already made my table with an column named Email, and the type is varchar(50), and when I try to add a row with a string of like "[email protected]" for the column Email, the row is nod added Commented Jul 11, 2012 at 17:06
  • that's does not describe your problem enough. Was there an error? Where is your code? Commented Jul 11, 2012 at 17:07
  • show the code where you try to add the row, so we can help Commented Jul 11, 2012 at 17:07

2 Answers 2

2

don't use sql injection, use parameterized queries instead.

command.CommandText = "insert into table (column) values(@p1)";
command.Parameters.AddWithValue("p1", "[email protected]");
Sign up to request clarification or add additional context in comments.

Comments

0

varchar should allow for the @ symbol, but for some symbols it requires nvarchar instead of varchar. nvarchar stores unicode and is used to support symbols outside of the ASCII range.

4 Comments

so I have to drop my table and built it again,that's the only way now?
If you are going to support international charachters you will probably have to recreate the table (or set the option to let the manager do it for you). I agree that parameterizing your query is best, but looking at your query, it should allow you to insert the @ symbol.
The option to allow the tool to recreate the table when you change the field type in Management Studio is Tools > Options > Designers and then uncheck the following option "Prevent saving changes that require table re-creation"
can't find designers option, hmmm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.