i tried to delete records from two tables that is joined, table A primary key
is ID
While table B forieng key is ShareID
so i did somthing like this, but didnt get that
[WebMethod]
public static void DeletUSERpostnow(int id, string username)
{
string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("DELETE USERPost, SHPOSTS FROM USERPost INNER JOIN SHPOSTS WHERE USERPost.ID= SHPOSTS.ShareId and USERPost.UserName =@UserName"))
{
cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"].ToString());
cmd.Parameters.AddWithValue("@ID", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}