protected void Button5_Click(object sender, EventArgs e)
{
if (TextBox3.Text != "")
{
this.conditions.Text += DropDownList2.SelectedItem + ":" + TextBox3.Text + ";";
string s="["+DropDownList2.SelectedValue+"]"+"="+"'"+TextBox3.Text+"'";
//集合存储新的条件
condit.Add(s); //用集合记录添加的条件
} } protected void Button8_Click(object sender, EventArgs e)
{
this.conditions.Text = "";
selcom = "";
condit = null;
} protected void Button7_Click(object sender, EventArgs e)
{
selcom = "SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where "; //以选填内容为查询条件执行查询
//从集合中添加查询条件
int a=condit.Count;
if (a > 1)
{
for (int i = 0; i < condit.Count-1; i++)
{
selcom += " "+condit[i] +" "+"and";
}
selcom += " "+condit[a - 1];
}
if (a == 1) { selcom+= " " + condit[0];}
//执行查询
SqlDataSource4.SelectCommand=selcom;
//"SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where "+condit[0]; 把selcom改为这句赋值数据绑定成功 //"SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where [m_toolType1]='立铣刀' " 把selcom改为这句赋值数据绑定同样成功
GridView1.DataSource = SqlDataSource4;
conditions.Text = SqlDataSource4.SelectCommand; //显示此时的SqlDataSource4.SelectCommand
GridView1.DataBind(); //当SqlDataSource4.SelectCommand=selcom;时错误在“&”附近出现语法错误
}
private static string selcom ;
private static ArrayList condit = new ArrayList();程序内容:以界面选填的条目为条件进行查询。选填条目个数、是哪一列都开始不确定。以集合condit存储添加的条件,最后把这些条件按格式加入查询语句中。
出现的问题如红色部分:把写好的字符串 变量 付给SqlDataSource4.SelectCommand绑定失败。但是把和这个变量当时的值直接 复制出来付给它就可以了。用上面的另外一种赋值也是可以的。郁闷,不知道为什么,常量可以,还有那个也可以,为什么有相同值的string变量就不可以呢?求解答!谢谢各位大侠~
{
if (TextBox3.Text != "")
{
this.conditions.Text += DropDownList2.SelectedItem + ":" + TextBox3.Text + ";";
string s="["+DropDownList2.SelectedValue+"]"+"="+"'"+TextBox3.Text+"'";
//集合存储新的条件
condit.Add(s); //用集合记录添加的条件
} } protected void Button8_Click(object sender, EventArgs e)
{
this.conditions.Text = "";
selcom = "";
condit = null;
} protected void Button7_Click(object sender, EventArgs e)
{
selcom = "SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where "; //以选填内容为查询条件执行查询
//从集合中添加查询条件
int a=condit.Count;
if (a > 1)
{
for (int i = 0; i < condit.Count-1; i++)
{
selcom += " "+condit[i] +" "+"and";
}
selcom += " "+condit[a - 1];
}
if (a == 1) { selcom+= " " + condit[0];}
//执行查询
SqlDataSource4.SelectCommand=selcom;
//"SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where "+condit[0]; 把selcom改为这句赋值数据绑定成功 //"SELECT [m_toolRFID] AS RFID编码, [m_toolName] AS 名称, [m_toolType1] as 类型, [m_toolMateial] as 材料, [m_diameter] as 直径, [m_worklength] as 工作长度, [m_teeth] as 齿数, [m_clamping] as 安装方式 FROM [m_toolInfo] where [m_toolType1]='立铣刀' " 把selcom改为这句赋值数据绑定同样成功
GridView1.DataSource = SqlDataSource4;
conditions.Text = SqlDataSource4.SelectCommand; //显示此时的SqlDataSource4.SelectCommand
GridView1.DataBind(); //当SqlDataSource4.SelectCommand=selcom;时错误在“&”附近出现语法错误
}
private static string selcom ;
private static ArrayList condit = new ArrayList();程序内容:以界面选填的条目为条件进行查询。选填条目个数、是哪一列都开始不确定。以集合condit存储添加的条件,最后把这些条件按格式加入查询语句中。
出现的问题如红色部分:把写好的字符串 变量 付给SqlDataSource4.SelectCommand绑定失败。但是把和这个变量当时的值直接 复制出来付给它就可以了。用上面的另外一种赋值也是可以的。郁闷,不知道为什么,常量可以,还有那个也可以,为什么有相同值的string变量就不可以呢?求解答!谢谢各位大侠~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货