请教asp.net连接sql2000
--------------------------------usingSystem;usingSystem.Data;usingSystem.Configuratio...
--------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
------------------------------------------
sqlconnection conn=new sqlconnection("server=.;databse=login;uid=sa;pwd=;");
conn.open();
sqlcommand cmd=new sqlcommand("select * from login");
response.write(conn);
------------------------------------------
数据库名是login 表名login
以上是连接数据库代码,运行结果没有把数据库表中的信息显示出来,而是显示:System.Data.SqlClient.SqlConnection
请问是为什么?哪里出错了吗?怎么解决! 请教!!!
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form["userName"].ToString();
string userPwd = Request.Form["userPwd"].ToString();
SqlConnection conn = new SqlConnection("server=.;database=Login;uid=sa;pwd=");
conn.Open();
SqlCommand cmd=new SqlCommand("select count(*) from login where userName='" +userName+"' and userPwd='" +userPwd+"'",conn);
//Response.Write(cmd);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("loginfail.aspx");
}
}
这样写哪里错了么?是不是连接数据库哪里出问题了 运行显示:未将对象引用设置到对象的实例 请教! 展开
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
------------------------------------------
sqlconnection conn=new sqlconnection("server=.;databse=login;uid=sa;pwd=;");
conn.open();
sqlcommand cmd=new sqlcommand("select * from login");
response.write(conn);
------------------------------------------
数据库名是login 表名login
以上是连接数据库代码,运行结果没有把数据库表中的信息显示出来,而是显示:System.Data.SqlClient.SqlConnection
请问是为什么?哪里出错了吗?怎么解决! 请教!!!
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form["userName"].ToString();
string userPwd = Request.Form["userPwd"].ToString();
SqlConnection conn = new SqlConnection("server=.;database=Login;uid=sa;pwd=");
conn.Open();
SqlCommand cmd=new SqlCommand("select count(*) from login where userName='" +userName+"' and userPwd='" +userPwd+"'",conn);
//Response.Write(cmd);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
Response.Redirect("main.aspx");
}
else
{
Response.Redirect("loginfail.aspx");
}
}
这样写哪里错了么?是不是连接数据库哪里出问题了 运行显示:未将对象引用设置到对象的实例 请教! 展开
2个回答
展开全部
SqlConnection conn = new SqlConnection("server=.;databse=login;uid=sa;pwd=;");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from login", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill("ds");
Response.Write(ds.Tables[0]);
da.Dispose();
conn.Close();
conn.Open();
SqlCommand cmd = new SqlCommand("select * from login", conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill("ds");
Response.Write(ds.Tables[0]);
da.Dispose();
conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询