标题:[求助]高手帮忙看看啊! 这一句总是说出现异常 myDataAdapter.Fill (ds,Dat ...
只看楼主
hyei1984
Rank: 2
等 级:论坛游民
帖 子:36
专家分:15
注 册:2007-3-26
 问题点数:0 回复次数:2 
[求助]高手帮忙看看啊! 这一句总是说出现异常 myDataAdapter.Fill (ds,DataTableN

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

namespace useDataGrid
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(64, 48);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(472, 160);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 269);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "使用DataGrid控件来显示数据";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\db1.mdb";

OleDbConnection myOleDbConnection= new OleDbConnection(connString);

string selectString = "SELECT * FORM 表1";

OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand ();

myOleDbCommand.CommandText = selectString;

OleDbDataAdapter myDataAdapter = new OleDbDataAdapter ();


myDataAdapter.SelectCommand = myOleDbCommand;


DataSet ds = new DataSet();
myOleDbConnection.Open ();
string DataTableName ="表1";
//ds.Clear ();
myDataAdapter.Fill (ds,DataTableName);

DataTable myDataTable = ds.Tables [DataTableName];


dataGrid1.DataSource = ds.DefaultViewManager;
}
}
}


这一句 出现异常 myDataAdapter.Fill (ds,DataTableName);
高手指教一下

[此贴子已经被作者于2007-3-28 22:42:37编辑过]

搜索更多相关主题的帖子: Fill DataTableN 
2007-03-28 21:55
hyei1984
Rank: 2
等 级:论坛游民
帖 子:36
专家分:15
注 册:2007-3-26
得分:0 
高手  99啊

2007-03-28 22:58
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
得分:0 
这种没有什么,找不到原因 就TRY一下再CATCH就出来结果了。

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2007-03-29 07:55



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




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

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