亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未將對象引用設置到對象實例!錯誤在private void BindData()函數里!該怎么解決?

未將對象引用設置到對象實例!錯誤在private void BindData()函數里!該怎么解決?

紅糖糍粑 2021-10-13 15:11:21
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.OleDb;using System.Data.SqlClient;namespace ConnectionDB{public partial class Form2 : Form{DataSet ds;int recordCount;public Form2(){BuildData();BindData();recordCount = this.BindingContext[ds, "StudentInfo"].Count;}private void BuildData(){string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\C#實驗\\ConnectionDB\\Database2.accdb";string str = "select * from [StudentInfo]";OleDbConnection conn = new OleDbConnection(constr);conn.Open();OleDbDataAdapter adapter = new OleDbDataAdapter(str, conn);OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);ds = new DataSet();adapter.Fill(ds, "StudentInfo");}private void BindData(){this.textBox1.DataBindings.Add(new Binding("Text", ds, "StudentInfo.SNo"));this.textBox2.DataBindings.Add(new Binding("Text", ds, "StudentInfo.Class"));this.textBox3.DataBindings.Add(new Binding("Text", ds, "StudentInfo.SName"));this.textBox4.DataBindings.Add(new Binding("Text", ds, "StudentInfo.Sgrade"));}private void Form2_Load(object sender, EventArgs e){}private void button2_Click(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){this.BindingContext[ds, "StudentInfo"].Position -= 1;}private void button3_Click(object sender, EventArgs e){this.BindingContext[ds, "StudentInfo"].Position -= 1;}}}
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

private void BuildData()
{
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\C#實驗\\ConnectionDB\\Database2.accdb";
string str = "select * from [StudentInfo]";
OleDbConnection conn = new OleDbConnection(constr);
try
{
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(str, conn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds, "StudentInfo");
}
catch (Exception)
{
throw;
}
}
看看輸出什么錯誤?



查看完整回答
反對 回復 2021-10-17
  • 1 回答
  • 0 關注
  • 204 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號