c#添加了Configuration;后,竟然找不到 ConfigurationManager 这个类,后来才发现:虽然引用了using System.Configuration;这个包,但是还是不行的。
后来终于找到一个解决方法,就是在解决方案资源管理器里找到类文件选择“引用”,然后右击选择“添加引用”,并且从 .net 中找到
System.Configuration把它加上去就OK啦,本人是在最近找到
- 实例:DataGridView显示数据
-
-
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
using DevExpress.XtraEditors;
-
using System.Data.SqlClient;
-
using System.Configuration;
-
-
namespace WindowsApplication1
- {
-
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
- {
-
public XtraForm1()
- {
- InitializeComponent();
- }
-
-
private void button1_Click(object sender, EventArgs e)
- {
-
string customers = "select * from Customers";
-
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString))
- {
-
-
DataSet dt = new DataSet();
-
SqlDataAdapter da = new SqlDataAdapter(customers, con);
-
da.Fill(dt, "Customers");
-
dataGridView1.AutoGenerateColumns = true;
- dataGridView1.DataSource = dt;
-
dataGridView1.DataMember = "Customers";
- }
- }
- }
- }
|
请发表评论