string strconn = "Data Source=PC-201104181242\\SQLEXPRESS;UID=sa;PWD=123;Database=hr";
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string strsql = "SELECT * FROM [hr].[dbo].[users],[hr].[dbo].[gerenxinxi] where userid='" + TextBox2.Text + "'and userpassword='" + TextBox1.Text + "'and [hr].[dbo].[users].id=[hr].[dbo].[gerenxinxi].id";//这里的查询语句是正确的
SqlCommand cm = new SqlCommand(strsql,cn);
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Session["userid"] = dr["userid"];
Session["id"] = dr["id"];
Session["name"] = dr["name"];
Session["shengqing_id"] = dr["shengqing_id"];
Session["userpassword"] = dr["userpassword"];
Session["userpower"] = dr["userpower"]; if ((TextBox1.Text.Trim() == Session["shengqing_id"].ToString().Trim()) && (TextBox2.Text.Trim() == Session["name"].ToString().Trim()))
{
string strsql = "INSERT INTO [hr].[dbo].[shenqing]([shengqing_id],[name],[peixun_bianhao]) VALUES ( '" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox7.Text + "') "; SqlCommand cm = new SqlCommand(strsql, cn); if ((cm.ExecuteNonQuery()) > 0)
{
this.Label1.Text = "信息插入成功!";
}
}
else
{
this.Label1.Text = "信息插入失败!";
}
cn.Close(); 为什么if的语句不是真,执行后显示的:信息插入失败!";
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string strsql = "SELECT * FROM [hr].[dbo].[users],[hr].[dbo].[gerenxinxi] where userid='" + TextBox2.Text + "'and userpassword='" + TextBox1.Text + "'and [hr].[dbo].[users].id=[hr].[dbo].[gerenxinxi].id";//这里的查询语句是正确的
SqlCommand cm = new SqlCommand(strsql,cn);
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Session["userid"] = dr["userid"];
Session["id"] = dr["id"];
Session["name"] = dr["name"];
Session["shengqing_id"] = dr["shengqing_id"];
Session["userpassword"] = dr["userpassword"];
Session["userpower"] = dr["userpower"]; if ((TextBox1.Text.Trim() == Session["shengqing_id"].ToString().Trim()) && (TextBox2.Text.Trim() == Session["name"].ToString().Trim()))
{
string strsql = "INSERT INTO [hr].[dbo].[shenqing]([shengqing_id],[name],[peixun_bianhao]) VALUES ( '" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox7.Text + "') "; SqlCommand cm = new SqlCommand(strsql, cn); if ((cm.ExecuteNonQuery()) > 0)
{
this.Label1.Text = "信息插入成功!";
}
}
else
{
this.Label1.Text = "信息插入失败!";
}
cn.Close(); 为什么if的语句不是真,执行后显示的:信息插入失败!";
解决方案 »
- chrome谷歌浏览器使用window.open()参数无法使用?
- 怎样捕获上传文件过大错误(FileUpload控件)
- 传说,这里有高手(不懂就问,无论何时)
- 。net文件中文名的问题
- ======关于一个用户控件的问题,求救~~~~~~~~~~
- 动态调用类或者方法,请高手帮忙
- 求助大家,GridView里面编辑项,怎么传到另外个页面进行修改
- 帮忙看一下哦!
- 客户端用window.open打开一个窗口下载文件,但下载完后窗口必须手动关闭,为什么?
- 如何通过一个Setup.exe的可执行文件就能将.Net Framework、虚拟目录设置和WEB程序一起安装呢??
- 朋友没帮我看看这个IF else循环有没有简单的方法
- 自定义控件无法触发click事件?
cm.Parameters.AddWithValue("@userid", TextBox2.Text);还有,在if(dr.Read())...else...之后要加上
dr.Close();