nad nad - 3 months ago 23
ASP.NET (C#) Question

ORA-00936: missing expression while using stringbuilder

I am using

StringBuilder
to use multiple queries in
asp.net
. But I am getting error as


ORA-00936: missing expression


Below is my query.

StringBuilder sb = new StringBuilder();
if (ddlProject.SelectedValue != "0" && ddlBuilding.SelectedValue != "0")
{
sb.Append("insert into xxacl_pN_LEASES_ALL_h select sysdate,* from xxacl_pN_LEASES_ALL");
sb.Append(";");
sb.Append("update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '" + ddlSalesUser.SelectedValue + "'");
sb.Append(";");
}
if (ddlProject.SelectedValue != "0" && ddlBuilding.SelectedValue == "0")
{
sb.Append("insert into xxacl_pN_LEASES_ALL_h select sysdate,* from xxacl_pN_LEASES_ALL");
sb.Append(";");
sb.Append("update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '" + ddlSalesUser.SelectedValue + "'");
sb.Append(";");
}

OracleConnection ObjPriCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString());
OracleCommand cmd1 = new OracleCommand();
string allQueries = sb.ToString();
cmd1.CommandText = allQueries;
cmd1.Connection = ObjPriCon;
ObjPriCon.Open();
cmd1.ExecuteNonQuery(); // here is the error caused
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Record updated successfully');window.location ='FrmHoldingCoordinateUpdate.aspx?TranType=FM&PView=N&Mode=A&Redirect=oracle&Key=0&Redirect=" + Request.QueryString["Redirect"] + "&userid=" + Request.QueryString["userid"].ToString() + "';", true);


Also,
allQueries
gives result as

insert into xxacl_pN_LEASES_ALL_h select getdate(),* from xxacl_pN_LEASES_ALL;update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '5681';

Answer

You need use alias for table name before * For example:

insert into xxacl_pN_LEASES_ALL_h  select getdate(),t.* from xxacl_pN_LEASES_ALL t;