标题:关与数据加载的问题?
取消只看楼主
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
 问题点数:0 回复次数:4 
关与数据加载的问题?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;

namespace Database
{
public partial class Form1 : Form
{
private OleDbConnection _Connection;
public Form1()
{
InitializeComponent();
}
private void Connect()
{
if (this .openFileDialog1 .ShowDialog ()==DialogResult .OK )
try
{
string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; User ID=;PassWord=;", this.openFileDialog1.FileName);
OleDbConnection newConnection = new OleDbConnection(connectionString);
newConnection.Open();
_Connection = newConnection;
MessageBox.Show("打开成功!");

}
catch (Exception ex)
{
HandleException("A Connect could not be made", ex);
}
}
public void HandleException(string message, Exception ex)
{
MessageBox.Show(this,string .Format ("{0}\n{1}:{2}",message ,ex .GetType ().ToString (),ex .Message ));
}
public OleDbConnection Connection
{
get
{
return _Connection;

}
set
{
Disconnect();
_Connection = value;
}
}
public void Disconnect()
{
if (_Connection != null)
{
if (_Connection.State != ConnectionState .Closed )
{
_Connection.Close();
_Connection = null;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{

}

private void connectToolStripMenuItem_Click(object sender, EventArgs e)
{
Connect();
}

private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
LoadData();
}
public void LoadData()
{
if (_Connection == null)
{
MessageBox.Show(this," you must connect database");
return;
}
OleDbCommand Command = null;
OleDbDataAdapter Adapter = null;
try
{
Command = _Connection.CreateCommand();
Command.CommandText = "Customers";
Command.CommandType = CommandType.TableDirect;
Adapter = new OleDbDataAdapter(Command);
DataSet dataset = new DataSet();
Adapter.Fill(dataset);
this.dataGridView1.DataSource = dataset;
MessageBox.Show("it is made");

}
catch (Exception ex)
{

HandleException("The data could not load", ex);
}
finally
{
if (Adapter != null)
{
Adapter.Dispose();
}
if (Command != null)
{
Command.Dispose();
}
}
}
}
}
各位帮我看哈,问题出在哪?都没有看出来的!我就纳闷数据怎么加载不上去呢?

搜索更多相关主题的帖子: using 加载 System 数据 public 
2007-11-13 23:17
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 
不是啊!我的意思是:让它打开后就加载数据上去的!

真的想象风一样去流浪!
2007-11-14 15:37
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 
靠!哥们还不行呢? 偶都看半天了,斗是没有看出来哪出问题了!晕求的很!

真的想象风一样去流浪!
2007-11-14 15:41
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 

你说的我试过了,还是不行的!看了半天,代码也没有错误,我就郁闷怎么加载不上数据呢!


真的想象风一样去流浪!
2007-11-15 10:18
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 

我已搞定了,谢谢大家了!我后来差了资料少了一个东西的!


真的想象风一样去流浪!
2007-11-20 09:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-185740-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.288705 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved