string myConnectString = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(myConnectString );
SqlConnection myConnection = new SqlConnection(myConnectString );
解决方案 »
- 语言C#,winform怎么实现combobox联动
- 超高分的超简单问题:DataGridView合并单元格的问题, 如何避免拖动滚动条时显示错乱?
- 这样的C#语句函数正确吗?
- 昨晚做梦突发奇想,发现C#2.0范型一个不合理的地方
- 以XML方式上传数据,服务接收后怎么判断每条记录的状态?
- 如何制作ie ActiveX (ie插件) 啊
- 这个问题怎么解决呢
- 为什么Drag事件全都失效了呀?AllowDrop也都设为True了呀,但是事件全都不触发呀???
- 当出现“错误 CS0122: “我的成绩系统.grade.成绩”不可访问,因为它受保护级别限制”应如何改正程序?
- 小弟新手弱弱的问一句应该从那个学起啊?
- 求大神。本人想做一个选中多个表。导出成XML格式的文件
- 怎么实现自动翻页操作
在DAL中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration ;
using System.Data;
namespace DAL
{
public class Class1DAL
{
public SqlDataReader show(string name)
{
//string c= System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
// SqlConnection conn = new SqlConnection( c );
string myConnectString = ConfigurationSettings.AppSettings["ConnectionString"]; SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();
String sql = string.Format("select 编号 from 学生表 where 姓名='{0}'", name);
SqlCommand cmd = new SqlCommand(sql, myConnection );
return cmd.ExecuteReader();
}
}
在 按控件butt1的代码using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
Class1DAL dal=new Class1DAL();
SqlDataReader dr = dal.show(TextBox1.Text);
if (dr.Read())
{
Response.Redirect("WebForm1.aspx");
}
else
{
Response.Write("用户名与密码不一致");
} }
}
}
最后是Web.config的代码 <appSettings>
<add key="ConnectionString" value="Data Source=levev-PC;Initial Catalog=student;Integrated Security=True"></add>
</appSettings>
能不能看下错在哪
一般用
using(SqlConnection myConnection = new SqlConnection( ))
{
................................
}
比较方便,不过现在基本都用SqlDataTable了 比较方便管理,虽然比SqlDataReader 慢一些,几乎可以忽略。。
<add key="ConnectionString" value="Data Source=levev-PC;Initial Catalog=student;User ID=sa;password=sa;Integrated Security=False"/>
</appSettings> public SqlDataReader show(string name)
{
string myConnectString = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();
String sql = string.Format("select StationID from StationPar where Area ='{0}'", name);
SqlCommand cmd = new SqlCommand(sql, myConnection);
return cmd.ExecuteReader(); }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration ;
using System.Data;
namespace DAL
{
public class Class1DAL
{
public SqlDataReader show(string name)
{
string myConnectString = ConfigurationSettings.AppSettings["ConnectionString"]; SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();
String sql = string.Format("select 编号 from 学生表 where 姓名='{0}'", name);
SqlCommand cmd = new SqlCommand(sql, myConnection );
return cmd.ExecuteReader();
}
}
}
然后是using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
Class1DAL dal=new Class1DAL();
Class1DAL da2=new Class1DAL();
SqlDataReader dr = dal.show(TextBox1.Text);
SqlDataReader da = da2.show(TextBox2.Text);
if (da.Read ()==dr .Read ())
{
Response.Redirect("1.aspx");
}
else
{
Response.Write("用户名与密码不一致");
} } protected void 取消_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
}
。为什么我有时候随便输入,都能登陆成功,有时候密码和账号都错了,还登陆成功。,哪里错了啊。、。。不知道怎么改