I am trying to execute a multi table delete in on sql query but I cant seem to get it right. the query is below. any help will be deeply appreciated. The ''id'' is already set from a different portion of the code.connection = Properties.Settings.Default.cvmanagerConnectionString;
sql = "delete from apps, contacts, dept using apps join contacts, join dept where apps.FileLoc = contacts.FileLoc AND apps.FileLoc = dept.FileLoc AND apps.FileLoc = ''" + id + "''";
try
{
SqlConnection conn = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
解决方案Judging from the examples here, it looks like you have an extra '','' in your query. I think it should be using apps join contacts join dept where
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=jcs-pc;Initial Catalog=deepak;Persist Security Info=True;User ID=sa;Password=jcs#");
SqlCommand cmd = new SqlCommand();
string s1 = "insert into deep (id,name)values(1,''sandeep'')";
string s2 = "insert into deep (id,name)values(1,''sandeep'')";
string s3 = "insert into sany (id,name'')values(1,''sandeep'')";
cmd.CommandText = s1 + s2 + s3;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
(sandeep.k115@gmail.com)