ASP .net中连接数据库是不是不宜用封装啊
为什么我看书上的例子 在每个按钮下都把 SqlConnection SqlCommand SqlReader写了一遍
然后我自己想用封装的方法 结果报错为 未将对象引用设置到对象的实例。
C# code:
public class DataAccess
{
public static string ConnStr="Data Source=.\\sqlexpress;Initial Catalog=学生信息管理;Integrated Security=True;Pooling=False";
public SqlDataReader GetReader(string sqlText)
{
SqlConnection conn = new SqlConnection(ConnStr);
SqlCommand command = new SqlCommand(sqlText,conn);
SqlDataReader dr = null;
try
{
conn.Open();
dr = command.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception e)
{
dr.Close();/[color=#FF0000]就是这里报错了[/color]
conn.Dispose();
command.Dispose();
throw new Exception(e.ToString());//
}
return dr;
}
}
这是登陆按钮下的事件
C# code:
protected void Btnlogin_Click(object sender, EventArgs e)
{
string name = this.TBname.Text.Trim();
string password = this.TBpwd.Text.Trim();
DataAccess da=new DataAccess();
string sqlText="select * from 用户信息 where 用户名=‘"+
相关问答:
有一个类
class adc
{
dim a,b,c
}
如何在另外一个类中取得类成员及成员个数
class getmenber
{
dim menbers()
function getmenbers(resclass)
'res为一未知类
'getmenber ......
本人不会asp,报错了,请大家帮忙看看。
代码如下:
<%
dim keyword_Name,keyword_YJ,keyword_RQ
if rs("QS_PASS_1_name")<>"0,0" then
keyword_Name=split(rs("QS_ ......
<?xml version="1.0"?>
<root>
<status>433</status>
<msg>这个是汉字</msg>
<serialno>123</serialno>
</root>
如何用ASP读取 status值 ......
现在客户需要在用户打开一个本地网页的时候,就要验证电脑的AD账号和数据库的其中一个账号吻合,请问我怎么来验证AD账号是否在数据库里面存在呢?
也就是这个系统在打开的时候,就要获得到AD账号和密码。然后进行登 ......
3个radioButton
一个Button
一个label
C# code:
protected void Button1_Click(object sender, EventArgs e)
{
string str = null;
RadioButton rdo=(RadioButton)sender;
......