我是这样写的 但是查出来不对的,是什么原因呢???是转换的问题吗? string j1 =Session["jj1"].ToString(); string j2 =Session["jj2"].ToString(); int jj1=0,jj2=1000000;if(j1.Length != 0){ jj1 = Convert.ToInt32(j1,16);} if(j2.Length != 0){jj2 = Convert.ToInt32(j2,16);}myCommand = new OleDbCommand( "select jj FROM lpan where (jj>="+jj1+" and jj<="+jj2+") ", myConnection );
//先验证用户输入//sql: "select * from t1 where filed1<=" + textBox1.text + " and field1>=" + textBox2.text
"select * from t1 where filed1<=" + textBox1.text.Trim() + " and field1>=" + textBox2.text.Trim()就这样 很简单的啊 LZ想多了吧
SqlCommand comm=conn.CreateCommand(); comm.CommandText="select * from 表名 where 1=1"; try { int fristNo = int.Parse(this.TextBox1.Text); int secondNO = int.Parse(this.TextBox2.Text); } catch (Exception e) { throw new Exception("请输入正确的数值"); } if (fristNo > secondNo) { comm.CommandText=comm.CommandText +"and 字段名 between secondNo and fristNO"; } else if(fristNo<secondNo) { comm.CommandText=comm.CommandText +" and 字段名 between fristNO and secondNo"; } else{ comm.CommandText=comm.CommandText+" and 字段名 = fristNo"; }
string j1 =Session["jj1"].ToString();
string j2 =Session["jj2"].ToString();
int jj1=0,jj2=1000000;if(j1.Length != 0){ jj1 = Convert.ToInt32(j1,16);}
if(j2.Length != 0){jj2 = Convert.ToInt32(j2,16);}myCommand = new OleDbCommand( "select jj FROM lpan where (jj>="+jj1+" and jj<="+jj2+") ", myConnection );
"select * from t1 where filed1<=" + textBox1.text + " and field1>=" + textBox2.text
"select * from t1 where filed1<=" + textBox1.text.Trim() + " and field1>=" + textBox2.text.Trim()就这样 很简单的啊 LZ想多了吧
comm.CommandText="select * from 表名 where 1=1";
try
{
int fristNo = int.Parse(this.TextBox1.Text);
int secondNO = int.Parse(this.TextBox2.Text);
}
catch (Exception e)
{
throw new Exception("请输入正确的数值");
}
if (fristNo > secondNo)
{
comm.CommandText=comm.CommandText +"and 字段名 between secondNo and fristNO";
}
else if(fristNo<secondNo)
{
comm.CommandText=comm.CommandText +" and 字段名 between fristNO and secondNo";
}
else{
comm.CommandText=comm.CommandText+" and 字段名 = fristNo";
}