我给你举一个例子,你看了就懂了,不懂的话加我QQ,一起交流!
string user = "";
string password = "";
SqlConnection con = new SqlConnection(connection);
con.Open();
try
{
sql = "select * from user_info where ID='" + this.tbuser.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader re = cmd.ExecuteReader();
if (re.Read())
{
user = (string)re.GetValue(0);
password = (string)re.GetValue(1);
}
else
{
Response.Write("");
}
bool jadge = string.Equals(password.Trim(), this.tbpassword.Text.Trim());
if (jadge)
{
Response.Write("");
Response.Redirect("~/Index.aspx");
}
else
{
Response.Write("");
}
con.Close();
}
catch
{
Response.Write("");
}
string s = "select * from table1";
sqlconnection conn=new sqlconnection();
SqlCommand com = new SqlCommand(s, conn);
问题一
1、通过datareader对象读取数据库中的数据
SqlDataReader dr = com.ExecuteReader();
dr.read();//只能读取第一条记录,如果不止一条,可通过while()循环。
2、可将查询结果绑定到gridview控件
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(s, c);
adp.Fill(ds);
gv.DataSource = ds.Tables[0];
问题二
t.substring(起始索引,子字符串长度);
t.subString(begin,end)