2011-04-27 4 views
1

cette erreur apparaît quand exécuter ce codeL'identifiant plusieurs parties ne pouvait être liée

 SqlConnection con = new SqlConnection(@"Data Source=SAMA-PC\SQLEXPRESS;Initial Catalog=meral10;Integrated Security=True"); 
     SqlCommand comsel = new SqlCommand("SELECT email from reg where email ="+email_tb.Text,con); 
     con.Open(); 
     comsel.ExecuteNonQuery(); 
     con.Close(); 
     if (comsel == null) 
     { 
      birthday = day_ddl.Text + "/" + month_ddl.Text + "/" + year_ddl.Text; 

      SqlCommand com = new SqlCommand("INSERT INTO reg(first_name,last_name,email,email_ver,pass,gender,birthday) values(@fn,@ln,@email,@reemail,@pass,@gen,@birth)", con); 
      con.Open(); 
      com.Parameters.AddWithValue("@fn", firstname_tb.Text); 
      com.Parameters.AddWithValue("@ln", lastname_tb.Text); 
      com.Parameters.AddWithValue("@email", email_tb.Text); 
      com.Parameters.AddWithValue("@reemail", reemail_tb.Text); 
      com.Parameters.AddWithValue("@pass", pass_tb.Text); 
      com.Parameters.AddWithValue("@gen", gender_ddl.SelectedItem.Text); 
      com.Parameters.AddWithValue("@birth", birthday); 
      com.ExecuteNonQuery(); 
      con.Close();} 

Répondre

2

Essayez de mettre des guillemets autour email_tb.Text, comme ceci:

"SELECT email from reg where email ='" + email_tb.Text + "'" 
2

Essayez:

SqlCommand comsel = new SqlCommand("SELECT email from reg where email ='" + email_tb.Text + "'", con) 

Eg votre chaîne littérale doit être entre guillemets. Mieux encore, utilisez un SqlParameter!

Questions connexes