public static string UserID
public static string Password
代码如下:
string sqlconn = "server = 220.162.131.160,1433database = sqlworkuid = sapwd = yxlbb520520"//数据库连接
string sqlqueryy = string.Format("select 账号,密码 from xs where 账号 = '{0}' and 密码 = '皮樱{1}'", textBox1.Text, textBox2.Text)
SqlConnection conn = new SqlConnection(sqlconn)
try
{
con.Open()
SqlCommand comm = new SqlCommand(sqlqueryy, con)
SqlDataReader ds = comm.ExecuteReader()
if (ds.Read())
{
userinfo1.UserID = ds[0].ToString()
userinfo1.Password = ds[1].ToString()
xs mf = new xs()
this.Hide()
mf.ShowDialog()
}
else
{
MessageBox.Show("用户名或密码错误!!!")
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message)
}
finally
{
con.Close()
}
protected DataSet ds = new DataSet() ds = DB.select("select * from [user] 这亏衡尘是表名 where [username]='" + userName 用户名输入框的id+ "' and [userpass]='" + userPassmd5这是密码的输入销禅框id + "'", "user")if (ds.Tables["拦悔user"].Rows.Count >0) 说明有这个账户、密码一样的记录
{
Session["userName"] = ds.Tables["user"].Rows[0]["username"].ToString() Response.Redirect("登录了")
}还得需要一个类db.cspublic static DataSet select(string sql,string tablename)
{
OleDbConnection conn = DB.Getconn()
OleDbDataAdapter adp = new OleDbDataAdapter(sql, conn)
DataSet ds = new DataSet()
adp.Fill(ds, tablename)
closeConnection()
return ds
}
用DataSet获得这个表记录,空记录也无所谓,这个DataSet便有了你指携要的那者此个表的首逗迅结构了,你便可以从ds中得到你想要的字段名称。比如你想得到第一列的字段名称:DataSet.Tables[0].Columns[0].ColumnName,第二列的字段名称:DataSet.Tables[0].Columns[1].ColumnName欢迎分享,转载请注明来源:内存溢出
评论列表(0条)