日期:2014-05-17 浏览次数:21003 次
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="abc" connectionString="server=.\\SQL2005; database=clxdb; integrated security=True"/>
</connectionStrings>
</configuration>
private void button1_Click(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
//
using (SqlConnection conn = new SqlConnection(str))
{MessageBox.Show(str);
if(conn!=null && conn.State!=ConnectionState.Open)
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from manager";
using(SqlDataReader reader=cmd.ExecuteReader())
while (reader.Read())
{
string strreader=reader.GetString(0);
MessageBox.Show(strreader);
}