vb工程中有两个text控件两个command控件,数据库用sqlsever2000,建立一个登录界面
数据库名是ysdd,表是yh,sql登录名是gbj密码是123,建立一个登录界面,代码是什么这是我的代码,但是里面缺了很多东西,而且不管输入什么都显示密码错,而且用户名错...
数据库名是ysdd,表是yh,sql登录名是gbj密码是123,建立一个登录界面,代码是什么
这是我的代码,但是里面缺了很多东西,而且不管输入什么都显示密码错,而且用户名错也不显示==,看看怎么改,不能改怎么重新写,详细的,谢谢
Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名密码不能为空"
End If
sql = "select * from yh where name='" & Text1.Text & "'"
If pass = "&text2.text&" Then
Form2.Show
Unload Me
Else
MsgBox "密码错误!"
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
conn.ConnectionString = "Driver={SQL Server};SERVER=glb;DATABASE=ysdd;UID=gbj;PWD=123"
conn.Open ("Provider=SQLOLEDB;Data Source=glb;UID=gbj;PWD=123")
End Sub 展开
这是我的代码,但是里面缺了很多东西,而且不管输入什么都显示密码错,而且用户名错也不显示==,看看怎么改,不能改怎么重新写,详细的,谢谢
Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "用户名密码不能为空"
End If
sql = "select * from yh where name='" & Text1.Text & "'"
If pass = "&text2.text&" Then
Form2.Show
Unload Me
Else
MsgBox "密码错误!"
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
conn.ConnectionString = "Driver={SQL Server};SERVER=glb;DATABASE=ysdd;UID=gbj;PWD=123"
conn.Open ("Provider=SQLOLEDB;Data Source=glb;UID=gbj;PWD=123")
End Sub 展开
2个回答
展开全部
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 Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//提交数据
//连接服务器
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Integrated Security=false;User ID=gbj;Password=123;Initial Catalog=ysdd";
conn.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "select * from yh where UserName=@a and UserPass=@b";
com.Parameters.Add("@a", tbname.Text);
com.Parameters.Add("@b", tbpass.Text);
com.Connection = conn;
SqlDataReader sdr = com.ExecuteReader();
if (sdr.Read())
Response.Redirect("index.aspx");
else
Response.Write("error");
conn.Close();
}
}
你试下这个代码吧!希望能帮到你!
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 Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//提交数据
//连接服务器
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Integrated Security=false;User ID=gbj;Password=123;Initial Catalog=ysdd";
conn.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "select * from yh where UserName=@a and UserPass=@b";
com.Parameters.Add("@a", tbname.Text);
com.Parameters.Add("@b", tbpass.Text);
com.Connection = conn;
SqlDataReader sdr = com.ExecuteReader();
if (sdr.Read())
Response.Redirect("index.aspx");
else
Response.Write("error");
conn.Close();
}
}
你试下这个代码吧!希望能帮到你!
展开全部
rs_login.Open "select * from manager where manager_id='" & Text1.Text & "'and manager_pwd='" & Text2.Text & "'", conn_info, adOpenDynamic, adLockOptimistic
If rs_login.RecordCount = 1 Then
MsgBox "OK", vbCritical, "提示"
Else
MsgBox "帐号或密码错误", vbCritical, "提示"
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End If
If rs_login.RecordCount = 1 Then
MsgBox "OK", vbCritical, "提示"
Else
MsgBox "帐号或密码错误", vbCritical, "提示"
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询