C# 选择查询sql C如何将结果输出到DataGrid
如何将优化查询的结果输出到名为customerDataGridView的datagrid视图C# 选择查询sql C如何将结果输出到DataGrid,c#,sql,datagridview,C#,Sql,Datagridview,如何将优化查询的结果输出到名为customerDataGridView的datagrid视图 string strCon = Properties.Settings.Default.PID2dbConnectionString; using (OleDbConnection conn = new OleDbConnection(strCon)) { conn.Open(); string strSql = "SELECT * FROM customer WHERE City =B
string strCon = Properties.Settings.Default.PID2dbConnectionString;
using (OleDbConnection conn = new OleDbConnection(strCon)) {
conn.Open();
string strSql = "SELECT * FROM customer WHERE City =Belfast";
OleDbDataAdapter adapter = new OleDbDataAdapter(new OleDbCommand(strSql, conn));
}
谢谢你的帮助 在ASP.Net中尝试类似的操作:
DataSet ds = new DataSet();
OleDbDataAdapter oledbAdapter = New OleDbDataAdapter(strSql, connection);
oledbAdapter.Fill(ds);
customerDataGridView.DataSource = ds.Tables(0);
customerDataGridView.DataBind();
或类似于WinForms的内容:
DataSet ds = new DataSet();
OleDbDataAdapter oledbAdapter = New OleDbDataAdapter(strSql, connection);
oledbAdapter.Fill(ds);
customerDataGridView.DataSource = ds.Tables(0);
祝你好运。请在编写代码后尝试以下操作:
DataTable table = new DataTable();
adapter.Fill(table);
customerDataGridView.AutoGenerateColumns = True
customerDataGridView.Datasource = table;
试试这个
DataSet ds = new DataSet();
OleDbDataAdapter oda = New OleDbDataAdapter(strSql, conn);
oda.Fill(ds);
customerDataGridView.DataSource = ds.Tables(0);
对于winform控件,您不需要.DataBind下的DataBind;我收到一个eror,上面说错误1“System.Windows.Forms.DataGridView”不包含“Databind”的定义,并且找不到接受“System.Windows.Forms.DataGridView”类型的第一个参数的扩展方法“Databind”。是否缺少using指令或程序集引用?请尝试删除Databind,windows窗体中可能不需要它。但请确保将dataGridView1.AutoGenerateColumns设置为True。指的是:。他们说数据源处理binding.under.databind;和ds.0;我收到一个eror,上面说错误1“System.Windows.Forms.DataGridView”不包含“Databind”的定义,并且没有扩展方法“Databind”接受类型为“System.Windows.Forms.DataGridView”的第一个参数,可以找到。您是否缺少using指令或程序集引用?我似乎没有类似的内容,最接近数据绑定的是数据绑定,也许我缺少一个库?你在使用WinForms吗?如果是这样,请查看此链接:是的,对不起,我没有在原始帖子中提到它。好的,谢谢。我去看看