nad nad - 2 months ago 7
ASP.NET (C#) Question

Update table if query has some value

I have a query which gives me a value, which is below

protected void CmdUpdate_Click(object sender, EventArgs e)
{
string query = "select mkey from xxacl_pN_LEASES_ALL where project_id = '" +
ddlProject.SelectedValue +
"' and " +
"building_id = '" +
ddlBuilding.SelectedValue +
"' and SALES_USER_ID = '" +
ddlSalesUser.SelectedValue +
"'";
}


Now what I want is, if query has some value then write the
update....
statement, which I know. If it doesn't then don't update the table.

I want how to check the condition whether query has values or not ?

update

My update statement

Update xxacl_pn_leases_all set ASSIGNED_TO = '' where mkey = query

Answer

try

Update xxacl_pn_leases_all set ASSIGNED_TO = '' where your_all_condition_here

e.g

Update xxacl_pn_leases_all set ASSIGNED_TO = '' where project_id = '" + ddlProject.SelectedValue + "' and "+
                    "building_id = '" + ddlBuilding.SelectedValue + "' and SALES_USER_ID = '" + ddlSalesUser.SelectedValue + "'";

above query will update rows which satisfied your condition.

N.B: Inline query is not good for practice, try using parameterize query instead.

Comments