2011-04-27 63 views
1

這個錯誤出現時,運行這段代碼多部分組成的標識符無法綁定

 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();} 

回答

2

嘗試把引號email_tb.Text,像這樣:

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

嘗試:

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

例如你的字符串文字需要用引號括起來。更好的是,使用SqlParameter!

相關問題