C#错误显示无定义DataBind和fill
privatevoidbutton2_Click(objectsender,EventArgse){stringsql=String.Format("SELECTFROM...
private void button2_Click(object sender, EventArgs e)
{
string sql = String.Format("SELECT FROM 帐薄 (时间,进账,项目1,支出,项目2) WHERE 时间 BETWEEN VALUES('{0}','{1}')", dateTimePicker2.Text, dateTimePicker3.Text);
SqlCommand cmd = new SqlCommand(sql, conn);
DataSet ds = new DataSet();
ds.fill(ds, "帐薄");
dataGridView1.DataSource = ds.Tables["帐薄"].DefaultView;
dataGridView1.DataBind();
conn.Open();
cmd.ExecuteNonQuery();
请问这句话要怎样修改呢?
显示错误是using System.Data.set不包含fill定义和using System.window.form.datagridview不包含DataBind定义
我前面用的是
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
还是有错误啊~显示
using System.Windows.Forms.DataGridView并不包含DataBind定义 展开
{
string sql = String.Format("SELECT FROM 帐薄 (时间,进账,项目1,支出,项目2) WHERE 时间 BETWEEN VALUES('{0}','{1}')", dateTimePicker2.Text, dateTimePicker3.Text);
SqlCommand cmd = new SqlCommand(sql, conn);
DataSet ds = new DataSet();
ds.fill(ds, "帐薄");
dataGridView1.DataSource = ds.Tables["帐薄"].DefaultView;
dataGridView1.DataBind();
conn.Open();
cmd.ExecuteNonQuery();
请问这句话要怎样修改呢?
显示错误是using System.Data.set不包含fill定义和using System.window.form.datagridview不包含DataBind定义
我前面用的是
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
还是有错误啊~显示
using System.Windows.Forms.DataGridView并不包含DataBind定义 展开
2个回答
展开全部
没有适配器啊,用下sqldataadapter
如果你已经有了SqlConnection conn,就照下面的写吧
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
string sql = String.Format("SELECT FROM 个人帐薄表 (时间,进账,项目1,支出,项目2) WHERE 时间 BETWEEN VALUES('{0}','{1}')", dateTimePicker2.Text, dateTimePicker3.Text);
SqlDataAdapter adpter = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
adpter.Fill(ds);
conn.Close();
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.DataBind();
}
这里不需要SqlCommand了,绑定的方法是DataBind(),而不是DataBindings()
如果你已经有了SqlConnection conn,就照下面的写吧
private void button2_Click(object sender, EventArgs e)
{
conn.Open();
string sql = String.Format("SELECT FROM 个人帐薄表 (时间,进账,项目1,支出,项目2) WHERE 时间 BETWEEN VALUES('{0}','{1}')", dateTimePicker2.Text, dateTimePicker3.Text);
SqlDataAdapter adpter = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
adpter.Fill(ds);
conn.Close();
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.DataBind();
}
这里不需要SqlCommand了,绑定的方法是DataBind(),而不是DataBindings()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询