protected void LinkButton2_Click(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection("server=(local);Database=sb_management;Uid=sa;Pwd=sa");
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string user = Session["sb_username"].ToString();
string uid = "select finding from view_authority where uid=" + user;
if (uid == "1")
{
Response.Write("<script language='javascript'>window.open(\"equipfind/mainfind_left.aspx\",\"main_left\");</script>");
}
else
{
Response.Write("<script>alert(\"对不起,您没有使用此功能的权限,请联系管理员!\");</script>");
return;
}
}
这段代码中有个问题,就是查询语句并没有执行,导致UID是个SQL语句而无法进行判断,请高手帮我把缺少的代码写上或者把代码改正!谢谢,这个问题我不知道该怎么描述,上网查也查不到答案!
{
//SqlConnection con = new SqlConnection("server=(local);Database=sb_management;Uid=sa;Pwd=sa");
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string user = Session["sb_username"].ToString();
string uid = "select finding from view_authority where uid=" + user;
if (uid == "1")
{
Response.Write("<script language='javascript'>window.open(\"equipfind/mainfind_left.aspx\",\"main_left\");</script>");
}
else
{
Response.Write("<script>alert(\"对不起,您没有使用此功能的权限,请联系管理员!\");</script>");
return;
}
}
这段代码中有个问题,就是查询语句并没有执行,导致UID是个SQL语句而无法进行判断,请高手帮我把缺少的代码写上或者把代码改正!谢谢,这个问题我不知道该怎么描述,上网查也查不到答案!
解决方案 »
- 在ListView1中,在操作中,客户用可以是点击ListView的行,获取行信息 会触发listView1_Click事件,可是客户也可能是用上下键移动选择的
- 100分 webservice 超时问题
- 如何让下拉列表框的第一个项目为选中状态
- 关于从excel导入到数据库的问题
- 拜托了,高手指点一下,用axWebBrowser内嵌EXCEL的打印预览问题
- 选中checkbox in gridview,如何让itemfield下面的所有items只读
- 求网站域名名称
- 启动程序后,如何监测其执行情况(是否正常执行、异常退出等等)?
- 谁知道FileField上传文件大小有限制吗?多大?谢谢?
- c#与access的操作,向原有数据中更新照片,出现这个错误,网上找了很多都不行
- 【100】TreeView 窗体调用 access
- 存储时间日期不能分别出上午下午啊?怎么办?在线等.....
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string user = Session["sb_username"].ToString();
SqlCommand command = new SqlCommand ("select finding from view_authority where uid=@uid", con);
command.Parameters.Add(new SqlParameter("@uid", user));
string ret = (string)command.ExecuteScalar();
if (ret == "1")
// 后面接你的代码
怎么可能为为1
你根本没有执行SQL语句啊
string query="SELECT FINDING FROM VIEW_AUTHORITY WHERE UID='"+USER+"'";
SqlCommand mycom=new SqlCommand(query,con);
mycom.CommandText = CommandType.Text;
string uid=(string)mycom.ExecuteScalar();
if(uid=="1")
{}
else
{}
----------------------
string uid = "select finding from view_authority where uid='" + user+"';
SqlCommand sqlcom=new SqlCommand(udi,con);
string result=conver.Tosting(sqlcom.ExecuteScalar());
result 就是查询到的结果。
返回一个值就用SqlCommand的ExecuteScalar()方法;
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string user = Session["sb_username"].ToString();
con.Open();
string query = "select finding from view_authority where uid='" + user + "'";
SqlCommand mycom = new SqlCommand(query, con);
mycom.CommandType = CommandType.Text;
string uid = (string)mycom.ExecuteScalar();
if (uid == "1"){}
con.Close();
在调试的时候string uid = (string)mycom.ExecuteScalar();提示无法将类型为“System.Boolean”的对象强制转换为类型“System.String”!请问要怎么解决呢?
string user = Session["sb_username"].ToString();
con.Open();
string query = "select finding from view_authority where uid='" + user + "'";
SqlCommand mycom = new SqlCommand(query, con);
mycom.CommandType = CommandType.Text;
string uid = mycomcom.ExecuteNonQuery().ToString();
if (uid == "1"){}
con.Close();
7楼的用法是错的,ExecuteNonQuery()方法是用来执行插入,删除,修改等SQL语句并返回影响的行数,如果是查询语句用它执行,那么不管你查询到多少条记录都是返回-1;所以不能用。
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string user = Session["sb_username"].ToString();
con.Open();
string query = "select finding from view_authority where uid='" + user + "'";
SqlCommand mycom = new SqlCommand(query, con); mycom.CommandType = CommandType.Text;
string uid = mycomcom.ExecuteScalar().ToString();
if (uid == "1"){}
con.Close();