首页 > 代码库 > ADO.net
ADO.net
string sqlcommand;
string TextValue = http://www.mamicode.com/TextBox1.Text.Trim();
SqlConnection sqlConnection = new SqlConnection("Data Source=61.155.215.29;Initial Catalog=JFX;Persist Security Info=True;User ID=sa;Password=d043fi439yh7ug87GHfgFTfd3HI23efdEWQDE"); //数据库连接字符串
if (!string.IsNullOrEmpty(TextValue))
{
sqlcommand = "select Id,LoginName,BusinessName,Phone,CreateTime From UserInfo where "
+ "LoginName=‘" + TextValue + "‘";
}
else
{
sqlcommand = "select Id,LoginName,BusinessName,Phone,CreateTime From UserInfo";
}
sqlConnection.Open();
//DataSet 绑定
SqlCommand sqlcom = new SqlCommand(sqlcommand);
SqlDataAdapter da = new SqlDataAdapter(sqlcommand, sqlConnection);
DataSet ds = new DataSet();
da.Fill(ds);
Repeater1.DataSource = ds;
//DataRead绑定
SqlCommand sqlcom = new SqlCommand(sqlcommand,sqlConnection);
SqlDataReader dr = sqlcom.ExecuteReader();
Repeater1.DataSource = dr;
Repeater1.DataBind();//数据绑定
ADO.net