Custom Query Issue
Posted: Sat Jun 08, 2013 1:29 pm
Can anyone please guide me in the right direction on this query. I have been trying to get it to work for a few days and for some reason the AddInParameters is not being used by the query???
I am trying to run this query for a DropDownList based upon the selected value of another DropDownList. I am getting the value from the first dropdown.... it just isn't working in the query (@InputValue)
this is the line that is not working(database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);)
If anyone has a better way to write this ...I am all ears... I am pretty much a hack at C#.
private void FillOWCollections(string inputvalue)
{
//Response.Write(inputvalue);
CommerceBuilder.Data.Database database = Token.Instance.Database;
string sql = ("SELECT DISTINCT InputValue AS InputValue2, InputFieldId FROM ac_ProductTemplateFields WHERE (InputFieldId = 696) AND (ProductId IN (SELECT ProductId FROM ac_ProductTemplateFields AS ac_ProductTemplateFields_1 WHERE (InputValue = '@InputVal'))) ");
DbCommand selectCommand = database.GetSqlStringCommand(sql);
database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);
using (IDataReader reader = database.ExecuteReader(selectCommand))
if (((System.Data.Common.DbDataReader)reader).HasRows)
{
//database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);
//ddlOWCollections.DataSource = reader;
ddlOWCollections.DataTextField = "InputValue2";
ddlOWCollections.DataValueField = "InputValue2";
ddlOWCollections.DataBind();
ddlOWCollections.Items.Insert(0, "--Select Collection--");
}
else
{
lblMsg.Text = "No Media Types found";
}
}
I am trying to run this query for a DropDownList based upon the selected value of another DropDownList. I am getting the value from the first dropdown.... it just isn't working in the query (@InputValue)
this is the line that is not working(database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);)
If anyone has a better way to write this ...I am all ears... I am pretty much a hack at C#.
private void FillOWCollections(string inputvalue)
{
//Response.Write(inputvalue);
CommerceBuilder.Data.Database database = Token.Instance.Database;
string sql = ("SELECT DISTINCT InputValue AS InputValue2, InputFieldId FROM ac_ProductTemplateFields WHERE (InputFieldId = 696) AND (ProductId IN (SELECT ProductId FROM ac_ProductTemplateFields AS ac_ProductTemplateFields_1 WHERE (InputValue = '@InputVal'))) ");
DbCommand selectCommand = database.GetSqlStringCommand(sql);
database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);
using (IDataReader reader = database.ExecuteReader(selectCommand))
if (((System.Data.Common.DbDataReader)reader).HasRows)
{
//database.AddInParameter(selectCommand, "@InputVal", System.Data.DbType.String, inputvalue);
//ddlOWCollections.DataSource = reader;
ddlOWCollections.DataTextField = "InputValue2";
ddlOWCollections.DataValueField = "InputValue2";
ddlOWCollections.DataBind();
ddlOWCollections.Items.Insert(0, "--Select Collection--");
}
else
{
lblMsg.Text = "No Media Types found";
}
}