帮同学搞个课程设计winform连接sqlserver2005
具体方法:
.添加App.config文件
2.在App.config文件中添加节点?>
HoverTreeSCJ 为数据库的名称
3.在项目Reference中添加引用 System.configuration
在文件中 添加引用 using System.configuration;
using System.Data.SqlClient;
4.获取App.config中的连接字符串
public string ConnString = System.Configuration.ConfigurationManager.AppSettings["connString"];
5.连接数据库,读取数据SqlConnection conn = new SqlConnection(ConnString); string strSql = "SELECT * FROM Basetb"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = strSql; cmd.Connection = conn; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { this.textBox1.Text = dr[0].ToString(); } } conn.Close();/* hovertree.top */
推荐:http://www.cnblogs.com/roucheng/p/DataGridView.html
转载请保留本文网址:
http://www.shaoqun.com/a/233849.html