WPF 连接SQLServer数据库
WPF 连接SQLServer数据库
public void ConnectionSQLServerFunc() { //连接数据库字符串 string strConn = "Data Source=.;Initial Catalog=MyTest;User ID=sa;Password=password1"; using (SqlConnection conn = new SqlConnection(strConn)) { try { //连接数据库 conn.Open(); //查询数据库语句 string commandStr = "select * from TM_EMPLOYEE"; //要对数据源执行的 SQL 语句或存储过程 SqlCommand sqlCmd = new SqlCommand(commandStr, conn); //表示一组数据命令和一个数据库连接,它们用于填充 System.Data.DataSet 和更新数据源。 SqlDataAdapter sqlDataAda = new SqlDataAdapter(sqlCmd); //数据的内存中缓存 DataSet daSet = new DataSet(); //将获取到的数据填充到数据缓存中 sqlDataAda.Fill(daSet); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } MessageBox.Show("Executing Finished"); }
相关推荐
lbyd0 2020-11-17
sushuanglei 2020-11-12
腾讯soso团队 2020-11-06
gaobudong 2020-11-04
yangkang 2020-11-09
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30