SQL连接数据库
程序员文章站
2024-01-30 11:58:52
SqlConnection conn = null; string conString = "Data Source=; Initial Catalog=数据库名;User ID=账户;Password=密码";//连接数据库的字符串 conn = new SqlConnection(conStri ......
sqlconnection conn = null; string constring = "data source=; initial catalog=数据库名;user id=账户;password=密码";//连接数据库的字符串 conn = new sqlconnection(constring); conn.open();//打开数据库连接 if (conn.state == connectionstate.open) { // console.writeline("数据库连接成功"); } string sql = "select * from le_calibration where mo='m0pwp2sma01001'"; sqldataadapter da = new sqldataadapter(sql, conn);//从数据库中查询 conn.close(); dataset ds = new dataset(); da.fill(ds, "product");//将数据填充到dataset datatable mytable = ds.tables["product"];