asp.net网站后台如何和sqlserver2005进行连接 数据库该如何建立?能给点提示吗?
publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve...
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected SqlConnection GetConnection()
{
string conn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myConn = new SqlConnection(conn);
return myConn;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
//与数据库的连接
SqlConnection conn = GetConnection();
conn.Open();
string sqlStr;
sqlStr = "select * from Tb_Login where UseName='" + Login1.UserName + "' and UsePassword='" + Login1.Password + "'";
SqlDataAdapter adp = new SqlDataAdapter(sqlStr, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
if (!(ds.Tables.Count < 0))
{
Response.Redirect("NavigatePage.aspx?UserName=" + Login1.UserName.ToString());
}
else
Response.Write("登录失败");
adp.Dispose();
ds.Dispose();
conn.Close();
不知道该如何建立数据库! 展开
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected SqlConnection GetConnection()
{
string conn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myConn = new SqlConnection(conn);
return myConn;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
//与数据库的连接
SqlConnection conn = GetConnection();
conn.Open();
string sqlStr;
sqlStr = "select * from Tb_Login where UseName='" + Login1.UserName + "' and UsePassword='" + Login1.Password + "'";
SqlDataAdapter adp = new SqlDataAdapter(sqlStr, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
if (!(ds.Tables.Count < 0))
{
Response.Redirect("NavigatePage.aspx?UserName=" + Login1.UserName.ToString());
}
else
Response.Write("登录失败");
adp.Dispose();
ds.Dispose();
conn.Close();
不知道该如何建立数据库! 展开
2个回答
展开全部
SqlConnection conn = new SqlConnection();
String connString = "server = 127.0.0.1; user=sa; password = sa";
conn.ConnectionString = connString;
conn.Open();
SqlCommand cmd = new SqlCommand(“create database AAA”);
cmd.Connection = conn;
执行后,重新连接即可!
String connString = "server = 127.0.0.1; user=sa; password = sa";
conn.ConnectionString = connString;
conn.Open();
SqlCommand cmd = new SqlCommand(“create database AAA”);
cmd.Connection = conn;
执行后,重新连接即可!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询