2016-04-24 4 views
-1

profile_tbからClient_tbまで多くのレコードを重複してコピーしたいと思います。 このコードは、SQL Serverで非常にうまく動作しますが、わかりません。次のコードは、asp.netのクライアントページの読み込みに追加されています。コマンドasqlをロードするにはどのようにコマンドsql insert codeを実行しますか?

のSQLコマンド:

iNSERT iNTO Client (ProfileID) 
Select Distinct ProfileId From Profile Where Not Exists (Select 1 From 
Client where Profile.ProfileID = Client.ProfileID) 

plzは私を助けて!

答えて

0

SqlConnection、SqlCommandクラスを調べます。

using (SqlConnection cn = new SqlConnection("your connection string")) { 
    SqlCommand cmd = new SqlCommand("INSERT iNTO Client (ProfileID) Select Distinct ProfileId From Profile Where Not Exists (Select 1 From Client where Profile.ProfileID = Client.ProfileID)", cn); 

    cn.Open(); 
    cmd.ExecuteNonQuery(); 
    cn.Close(); } 

私はあなたがよりしかし、SqlCommandオブジェクトに見て、これは、ウェブサイトのコードであれば、SQLインジェクション攻撃を防御するためのパラメータのアプローチを使用することをお勧め。

関連する問題