1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
string M_str_sqlstr = "SQL查询语句";
SqlConnection sqlcon = this.getcon();
SqlDataAdapter sqlda = new SqlDataAdapter(M_str_sqlstr,sqlcon);
DataSet myds = new DataSet();
sqlda.Fill(myds,M_str_sqlstr);
DataTable dt = myds.Tables[0];
foreach (DataRow row in dt.Rows)
{
Client client = new Client();
client.ClientID = (int)row["ClientID"];
client.CName = (string)row["CName"];
clientlist.Add(client);
}
//数据库连接
private SqlConnection getcon()
{
string connString = "Data Source=.;Initial Catalog=Csharp;Integrated Security=True";
SqlConnection connection = new SqlConnection(connString);
return connection;
}
|