//创建连接
string constr = @"server=ipAddress;database=dbName;uid=idName;pwd=password";
conn = new SqlConnection(constr);
//创建查询
SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM tableName", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
//输出结果
sda.Fill(ds, "tableName");
int count = 0;
int.TryParse((ds.Tables["cs"].Rows[0][0]).ToString(), out count);
Console.WriteLine(count);
//关闭连接l
conn.Close();
C#连接mysql
最新推荐文章于 2024-06-09 12:39:36 发布