SqlConnection cn=new SqlConnection("server=localhost;database=drp2;uid=sa;pwd=zt;");
string sql="SELECT * from admin where username='"+this.TextBox1.Text+"' and password='"+ this.TextBox2.Text+"'";
SqlDataAdapter da=new SqlDataAdapter(sql,cn);
DataSet ds=new DataSet();
da .Fill(ds,"admin");
if(ds.Tables["admin"].Rows.Count!=0)
Response.Redirect("zym.aspx");
else
Response.Redirect("Default.aspx");
你写的数据库连接的位置不对,应该是写在button的时间里,
就是双击你在登陆页面的确定按键然后跳到index.aspx.cs文件里的位置。
上面是c#实现的语句。你只有把if 循环换成vb里的循环语句就能实现。
string sql="SELECT * from admin where username='"+this.TextBox1.Text+"' and password='"+ this.TextBox2.Text+"'";
SqlDataAdapter da=new SqlDataAdapter(sql,cn);
DataSet ds=new DataSet();
da .Fill(ds,"admin");
if(ds.Tables["admin"].Rows.Count!=0)
Response.Redirect("zym.aspx");
else
Response.Redirect("Default.aspx");
你写的数据库连接的位置不对,应该是写在button的时间里,
就是双击你在登陆页面的确定按键然后跳到index.aspx.cs文件里的位置。
上面是c#实现的语句。你只有把if 循环换成vb里的循环语句就能实现。
Imports System.Data.SqlClient
'put it to your first line
System.Data.SqlClient
即可
Imports System.Data.SqlClient
行 32: mycomm = New SqlCommand(strsql)
行 33: Dim reader As SqlDataReader
行 34: reader = mycomm.ExecuteReader() (提示错误在这一行)
行 35: If reader.Read() Then
行 36: Response.Write(reader("pwd"))
源文件: d:\inetpub\wwwroot\course\login.aspx.vb 行: 34 堆栈跟踪:
[InvalidOperationException: ExecuteReader:Connection 属性尚未初始化。]
System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing) +251
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +103
System.Data.SqlClient.SqlCommand.ExecuteReader() +11
course.login.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\course\login.aspx.vb:34
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
应该在程序的最上部加入程序的名称空间
imports system
imports system.data
imports system.data.sqlclient这样的话,在程序中就可以直接用了
'open DB
dim myConn as sqlconnection
dim connectString as string
connectString="connect string"
myconn=new sqlconnection(connectString)
myconn.open '
dim myCmd as sqlcommand
dim sql as string
sql="sql 2000 语句"
mycmd =new sqlcommand(sql,connectString)dim myReader as sqldataReader
myreader=mycmd.executereaderif myreader.read then
str1=myreader.getvalue(0)'user name
str2=myreader.getvalue(1)'password
end if然后进行比较就ok了。
行 32: mycomm = New SqlCommand(strsql)
行 33: Dim reader As SqlDataReader
行 34: reader = mycomm.ExecuteReader() (提示错误在这一行)
行 35: If reader.Read() Then
行 36: Response.Write(reader("pwd"))
源文件: d:\inetpub\wwwroot\course\login.aspx.vb 行: 34
这个问题还是没有解决啊!
看到错在哪里了 Dim myconn As SqlConnection = New SqlConnection(strconn)
(这一行多余)myconn = New SqlClient.SqlConnection(strconn)
myconn.Open()
Dim strsql As String
strsql = "select pwd from manager where manager_id='wzp' "
Dim mycomm As SqlCommand = New SqlCommand(strsql, myconn)
(这一行也多余,并且少个参数)mycomm = New SqlCommand(strsql)谢谢了,谢谢大家!!结贴!!