//数据库连接字符串
private static string source = @"Data Source = me-PC;DataBase=数据库名;User ID= server用户名;Pwd=server 密码;"; //用server用户名登录 //
//private static string source = "server = (loacl);" + "integrated security=SSPI;" + "database =数据库名 "; //用windows用户名登录
//数据库连接对象
public static SqlConnection connection = new SqlConnection(source);
public void SqlIPRead()
{
//string sql = "select ID,IP,Rack,Solt from IP where ID=1"; // string sql = "select 列名1,列名2,列名3,列名4 from 表名 where 查询条件";
string sql = "select ID,IP,Rack,Solt from IP"; // string sql = "select 列名1,列名2,列名3,列名4,列名5 from 表名 where 查询条件";
using (SqlCommand command = new SqlCommand(sql, connection)) //指定要执行的SQL语句
在C#中通过语句,读取数据库中的数据
最新推荐文章于 2024-05-08 19:05:41 发布