using System;
using System.Data;
using System.Configuration;
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;public partial class _Default : System.Web.UI.Page
{ protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "server=Localhost;uid=sa;pwd=;database=dzmusic";
string strCmd="select count(*) from admin where Username ='"+ TextBox1.Text +"' and Password = '"+ TextBox2.Text +"'";
SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;
myConnection.Command=new sqlCommand(strCmd,myConnection);
myCommand.Connection.open(); int flag=(int)myCommand.ExecuteScalar();
myConnection.Connection.Close();
if (flag>0)
{
Session["username"]=TextBox1.Text;
Response.Redirect("default2.aspx");
}
else
{
Lable1.Text="对不起!";
TextBox2.Text="";
}
}
}
怎么修改?using System.Data.SqlClient.SqlConnection怎么不能继承这个类?
using System.Data;
using System.Configuration;
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;public partial class _Default : System.Web.UI.Page
{ protected void Button1_Click(object sender, EventArgs e)
{
string strConn = "server=Localhost;uid=sa;pwd=;database=dzmusic";
string strCmd="select count(*) from admin where Username ='"+ TextBox1.Text +"' and Password = '"+ TextBox2.Text +"'";
SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;
myConnection.Command=new sqlCommand(strCmd,myConnection);
myCommand.Connection.open(); int flag=(int)myCommand.ExecuteScalar();
myConnection.Connection.Close();
if (flag>0)
{
Session["username"]=TextBox1.Text;
Response.Redirect("default2.aspx");
}
else
{
Lable1.Text="对不起!";
TextBox2.Text="";
}
}
}
怎么修改?using System.Data.SqlClient.SqlConnection怎么不能继承这个类?
解决方案 »
- 100分请教登录查询效率的问题
- 做网站问题,大家帮帮忙啊;申请好空间,域名。是不是还得申请数据库空间啊,怎么连接啊。那位大哥大姐做过,给小弟讲讲啊,谢谢了~!
- 请问各位大侠,在asp.net中,如果我要做动态的连接线,要怎么写代码?是不是要用好控件还是怎么用
- 伪静态做好以后,程序本地运行没问题,网上找不到路径,什么原因?急!
- 进来,我用分砸你!!问很垃圾~!~!~!很垃圾的~!~!~!很垃圾的~!·~!~!~很垃圾的~!~!~问题::
- 好可怜,竟然不知OJB.NET如何使用
- listbox样式问题,怎么加个黑边?
- OWC10问题,在线等
- 一个匿名登录跳转的问题
- 如何屏蔽超链接在状态栏显示的Url?
- Request.QueryString传值很不爽?
- 两个问题
SqlConnection conn = new SqlConnection(connString);
conn.Open();
SqlCommand Cmd = new SqlCommand(SQL, conn);
SqlDataAdapter da = new SqlDataAdapter(Cmd);
你定义的是myConnect没有定义myConnection
myConnection.ConnectionString=strConn;
==========================================楼主,你点不出来属性的时候代码就不用敲下去了...还有,你这种判断存在典型的SQL注入漏洞
SqlConnection myConnect = new SqlConnection();
myConnection.ConnectionString=strConn;//改为myConnect.ConnectionString=strConn;//