首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小弟问一个关于dataGrid1 的有关问题 大家帮帮忙吧 困扰小弟好几天了.

2012-03-09 
小弟问一个关于dataGrid1 的问题大家帮帮忙吧 困扰小弟好几天了....usingSystemusingSystem.Drawingusin

小弟问一个关于dataGrid1 的问题 大家帮帮忙吧 困扰小弟好几天了....
using   System;
using   System.Drawing;
using   System.Collections;
using   System.ComponentModel;
using   System.Windows.Forms;
using   System.Data;
using   System.Data.OleDb;


namespace   WindowsApplication1
{
///   <summary>
///   Form5   的摘要说明。
///   </summary>
public   class   Form5   :   System.Windows.Forms.Form
{
private   System.Windows.Forms.Label   label1;
private   System.Windows.Forms.TextBox   textBox1;
private   System.Windows.Forms.Button   button1;
private   System.Windows.Forms.Button   button2;
private   DataSet   ds=new   DataSet();
private   string   Afile;
private   OleDbConnection   Conn;
//private   System.Windows.Forms.Button   updata_button;
//private   System.Windows.Forms.Button   del_botton;
private   string   sss= " ";

///   <summary>
///   必需的设计器变量。
///   </summary>
private   System.ComponentModel.Container   components   =   null;

public   Form5()
{
//
//   Windows   窗体设计器支持所必需的
//
InitializeComponent();

//
//   TODO:   在   InitializeComponent   调用后添加任何构造函数代码
//
}

///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   Dispose(   bool   disposing   )
{
if(   disposing   )
{
if(components   !=   null)
{
components.Dispose();
}
}
base.Dispose(   disposing   );
}

#region   Windows   窗体设计器生成的代码
///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{
this.label1   =   new   System.Windows.Forms.Label();
this.textBox1   =   new   System.Windows.Forms.TextBox();
this.button1   =   new   System.Windows.Forms.Button();
this.button2   =   new   System.Windows.Forms.Button();
this.SuspendLayout();
//  
//   label1
//  
this.label1.Font   =   new   System.Drawing.Font( "宋体 ",   15F,   System.Drawing.FontStyle.Bold,   System.Drawing.GraphicsUnit.Point,   ((System.Byte)(134)));
this.label1.Location   =   new   System.Drawing.Point(40,   48);
this.label1.Name   =   "label1 ";
this.label1.Size   =   new   System.Drawing.Size(376,   40);
this.label1.TabIndex   =   0;
this.label1.Text   =   "请输入您要查询的学生选课情况的学号 ";
//  
//   textBox1
//  
this.textBox1.Location   =   new   System.Drawing.Point(152,   112);
this.textBox1.Name   =   "textBox1 ";
this.textBox1.Size   =   new   System.Drawing.Size(184,   21);
this.textBox1.TabIndex   =   1;
this.textBox1.Text   =   " ";
this.textBox1.TextChanged   +=   new   System.EventHandler(this.textBox1_TextChanged);
//  
//   button1
//  


this.button1.Font   =   new   System.Drawing.Font( "宋体 ",   15.75F,   System.Drawing.FontStyle.Bold,   System.Drawing.GraphicsUnit.Point,   ((System.Byte)(134)));
this.button1.Location   =   new   System.Drawing.Point(224,   256);
this.button1.Name   =   "button1 ";
this.button1.Size   =   new   System.Drawing.Size(88,   40);
this.button1.TabIndex   =   2;
this.button1.Text   =   "确定 ";
this.button1.Click   +=   new   System.EventHandler(this.button1_Click);
//  
//   button2
//  
this.button2.Font   =   new   System.Drawing.Font( "宋体 ",   15F,   System.Drawing.FontStyle.Bold,   System.Drawing.GraphicsUnit.Point,   ((System.Byte)(134)));
this.button2.Location   =   new   System.Drawing.Point(360,   256);
this.button2.Name   =   "button2 ";
this.button2.Size   =   new   System.Drawing.Size(80,   40);
this.button2.TabIndex   =   3;
this.button2.Text   =   "取消 ";
this.button2.Click   +=   new   System.EventHandler(this.button2_Click);
//  
//   Form5
//  
this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);
this.ClientSize   =   new   System.Drawing.Size(560,   414);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name   =   "Form5 ";
this.Text   =   "Form5 ";
this.ResumeLayout(false);

}
#endregion

private   void   look()
{
Afile= "provider=Microsoft.Jet.OLEDB.4.0;Data   Source=pass_word.mdb ";
Conn=new   OleDbConnection(Afile);
string   sqlcmd= "select   student     from   [student1]   where   num= ' "+textBox1.Text+ " ' ";
OleDbCommand   cmd=new   OleDbCommand(sqlcmd,Conn);
Conn.Open();
try
{
cmd.ExecuteNonQuery();
}
catch(Exception   a)
{
MessageBox.Show(a.ToString());
}
OleDbDataAdapter   dsa=new   OleDbDataAdapter(sqlcmd,Conn);
ds.Clear();
dsa.Fill(ds, "student ");
Conn.Close();
if(ds.Tables[0].Rows.Count==0)//判断查询结果是否为空
{
MessageBox.Show( "对不起,没有您要查询的信息 ", "错误!!! ");

}
dataGrid1.DataSource=ds.Tables[ "student "].DefaultView;
dataGrid1.SetDataBinding(ds, "student ");

}


             
private   void   button1_Click(object   sender,   System.EventArgs   e)
{
if(textBox1.Text== " ")
{
MessageBox.Show( "请输入查询信息 ", "错误!!! ");
}
else  
{
look();
        textBox1.Clear();
}
}

private   void   textBox1_TextChanged(object   sender,   System.EventArgs   e)
{

}

private   void   button2_Click(object   sender,   System.EventArgs   e)
{
this.Close();
}
}
}


上面的为源代码,在编译的时候出现错误,提示为:
C:\Documents   and   Settings\victor\桌面\选课\WindowsApplication1\Form5.cs(153):   找不到类型或命名空间名称“dataGrid1”(是否缺少   using   指令或程序集引用?)


C:\Documents   and   Settings\victor\桌面\选课\WindowsApplication1\Form5.cs(154):   找不到类型或命名空间名称“dataGrid1”(是否缺少   using   指令或程序集引用?
也就是       dataGrid1.DataSource=ds.Tables[ "student "].DefaultView;
                  dataGrid1.SetDataBinding(ds, "student ");
这两句有错误!
小弟在此先谢谢各位大哥了。。。


[解决办法]
你的dataGrid1在哪里定义了??
没定义你就用
[解决办法]
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;

---------------------------------------------------
確實沒有定義????丟了???

热点排行