我想和Webform  差不多!
DataView curview;
DataGrid.DataSource=curview;
DataGrid.DataBind();
只要更新curview就可以改变DataGrid!
至于用ACCESS,网上有很多例子!

解决方案 »

  1.   

    数据库连接
    Standard Security:
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=somepathmydb.mdb;Uid=Admin;Pwd=asdasd;" Workgroup:
    "Driver={Microsoft Access Driver (*.mdb)};Dbq=somepathmydb.mdb;SystemDB=somepathmydb.mdw;","admin", "" 
      

  2.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    this.carDate.Visible=false;
    this.tbDate.Text=System.DateTime.Now.ToString("yyyy/MM/dd");
    this.lbDate.Text="";
    this.lbTitle.Text="";
    this.ddlSEA.Visible=false; if (this.Session["jb"].ToString().Trim()=="manager")
    {
    getSection();
    this.ddlSEA.Visible=true;
    } }
    //this.subDate. }
    private void getSection()
    {
    DataView bdSection=gyC.getData("select hmsection from humanserver.humansys.dbo.human group by hmsection order by hmsection");
    int i;
    for(i=0;i<bdSection.Table.Rows.Count;i++)
    {
    this.ddlSEA.Items.Add(bdSection.Table.Rows[i]["hmsection"].ToString().Trim());
    this.ddlSEA.Items[i+1].Value=bdSection.Table.Rows[i]["hmsection"].ToString().Trim();
    }
       
    }
    private void carDate_SelectionChanged(object sender, System.EventArgs e)
    {
    string seDateTime=this.carDate.SelectedDate.ToString("yyyy/MM/dd");
    this.tbDate.Text=seDateTime;
    this.carDate.Visible=false;
    } private DataView getView()
    {
    string strSea="select c.cddate cddate,c.cdline cdline,c.cdcardno cdcardno,c.cdname cdname,c.time1 time1,c.time2 time2";
    strSea+=",c.time3 time3,c.time4 time4,c.time5 time5,c.time6 time6,c.ys ys from humanserver.humansys.dbo.cards c ";
    strSea+="left join humanserver.humansys.dbo.human h on c.cdname=h.hmname where h.hmsection='"+this.Session["section"].ToString()+"'";
    strSea+="and rtrim(c.ys)<>'' and convert(char(10),c.cddate,111)='"+this.tbDate.Text+"' order by c.cdline";
    //Response.Write(strSea); if (this.Session["jb"].ToString().Trim()=="manager")
    {
    if (this.ddlSEA.SelectedItem.Value.ToString().Trim()=="all")
    {
    strSea="select convert(char(10),c.cddate,111) cddate,c.cdline cdline,c.cdcardno cdcardno,c.cdname cdname,c.time1 time1,c.time2 time2";
    strSea+=",c.time3 time3,c.time4 time4,c.time5 time5,c.time6 time6,c.ys ys from humanserver.humansys.dbo.cards c ";
    strSea+="left join humanserver.humansys.dbo.human h on c.cdname=h.hmname where ";
    strSea+="rtrim(c.ys)<>'' and convert(char(10),c.cddate,111)='"+this.tbDate.Text+"' order by c.cdline";
    }
    else
    {
    strSea="select c.cddate cddate,c.cdline cdline,c.cdcardno cdcardno,c.cdname cdname,c.time1 time1,c.time2 time2";
    strSea+=",c.time3 time3,c.time4 time4,c.time5 time5,c.time6 time6,c.ys ys from humanserver.humansys.dbo.cards c ";
    strSea+="left join humanserver.humansys.dbo.human h on c.cdname=h.hmname where h.hmsection='"+this.ddlSEA.SelectedItem.Value.ToString().Trim()+"'";
    strSea+="and rtrim(c.ys)<>'' and convert(char(10),c.cddate,111)='"+this.tbDate.Text+"' order by c.cdline"; } } seDV=gyC.getData(strSea);
    int i;
    //DateTime bjDate;
    string bjStr; for(i=0;i<seDV.Table.Rows.Count;i++)
    {
    //Response.Write("SELECT * FROM CardsTemp WHERE convert(char(10),CdDate,111)=convert(char(10),"+seDV.Table.Rows[i]["cddate"].ToString().Trim()+",111) AND CdCardNo='"+seDV.Table.Rows[i]["cdcardno"]+"' AND updatestatus=0"); //bjDate=(DateTime)seDV.Table.Rows[i]["cddate"];
    //bjStr=bjDate.Year+"/"+bjDate.Month+"/"+bjDate.Day;
    bjStr=seDV.Table.Rows[i]["cddate"].ToString().Trim(); if (gyC.getData("SELECT * FROM CardsTemp WHERE convert(char(10),CdDate,111)='"+bjStr.Trim()+"' AND CdCardNo='"+seDV.Table.Rows[i]["cdcardno"]+"' AND (updatestatus=0 or updatestatus=1)").Table.Rows.Count>0)
    {
    if (seDV.Table.Rows[i]["time1"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time1"]="待人事確認";
    if (seDV.Table.Rows[i]["time2"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time2"]="待人事確認";
    if (seDV.Table.Rows[i]["time3"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time3"]="待人事確認";
    if (seDV.Table.Rows[i]["time4"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time4"]="待人事確認";
    if (seDV.Table.Rows[i]["time5"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time5"]="待人事確認";
    if (seDV.Table.Rows[i]["time6"].ToString().Trim().Length<1)
    seDV.Table.Rows[i]["time6"]="待人事確認";                    
    }
    } return seDV;
                
    }
    private void DG1BD()
    {
    this.DG1.Visible=true;
    this.DG1.DataSource=(DataView)this.Session["sessDV"];
    this.DG1.DataBind();
    }
      

  3.   

    myConn = new OleDbConnection(connStr);
    myDataAdapter = new OleDbDataAdapter();
    myDataAdapter.SelectCommand = new OleDbCommand("SELECT * FROM TABLE", myConn);
    myCommandBuilder = new OleDbCommandBuilder(myDataAdapter);myConn.Open();
    myDataAdapter.Update(myDataSet.Tables[0].GetChanges());
    myConn.Close();
      

  4.   

    http://dev.csdn.net/user/Latitude
    去看一下!只不过是VB的!!
      

  5.   

    http://www.cnblogs.com/icesnaker/archive/2004/07/31/29017.aspx
    也有一些深入的!!
      

  6.   

    private string sql="select * from cc_students";
    private string cnn=@"Integrated Security=SSPI;Packet Size=4096;Data Source=localhost;Tag with column collation when possible=False;Initial Catalog=Book;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=FEI;Use Encryption for Data=False";

    private System.Data.DataSet ccDS;
    private System.Data.OleDb.OleDbDataAdapter ccDA,ccDA2;
    private System.Data.OleDb.OleDbCommandBuilder  ccCMD;
    private System.Windows.Forms.BindingManagerBase mybind; /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void label13_Click(object sender, System.EventArgs e)
    {

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

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

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

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

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

    } private void Form1_Load(object sender, System.EventArgs e)
    {
    try
    {
    this.ccDS = new DataSet();
    this.ccDA = new System.Data.OleDb.OleDbDataAdapter(sql,cnn);
    this.ccDA.Fill(this.ccDS,"cc_students");
    this.ccCMD = new System.Data.OleDb.OleDbCommandBuilder(this.ccDA);
    this.mybind = this.BindingContext[this.ccDS,"cc_students"];
    this.dataGrid1.DataSource = this.ccDS;
    this.dataGrid1.DataMember = "cc_students";
    //绑定控件
    this.txtNO.DataBindings.Add("Text",this.ccDS,"cc_students.stu_no");
    this.txtPrice.DataBindings.Add("Text",this.ccDS,"cc_students.stu_addr");
    this.txtName.DataBindings.Add("Text",this.ccDS,"cc_students.stu_name");
    this.txtCB.DataBindings.Add("Text",this.ccDS,"cc_students.stu_DS");
    this.txtSort.DataBindings.Add("Text",this.ccDS,"cc_students.stu_sort");
    this.txtTime.DataBindings.Add("Text",this.ccDS,"cc_students.stu_addtime");

    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    } private void btnPre_Click(object sender, System.EventArgs e)
    {
    if (this.mybind.Position>0)
    this.mybind.Position-=1;
    else
    MessageBox.Show("当前记录已经是第一条","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
    } private void btnNext_Click(object sender, System.EventArgs e)
    {
    if (this.mybind.Position<this.mybind.Count-1)
    this.mybind.Position+=1;
    else
    MessageBox.Show("当前记录已经是最后一条","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
    } private void btnDelete_Click(object sender, System.EventArgs e)
    {
    Delete();
    }

    public void Delete()
    {
    // TODO:  添加 UserControl1.Delete 实现
    //MessageBox.Show("Test?ok");
    if(this.txtNO.Text =="")
    {
    MessageBox.Show("没有数据可以被删除","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information  );
    return;
    }
    string msg = "您确定要删除选定的记录吗?"; if(MessageBox.Show(msg, "图书管理系统", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No )
    return ;
    try
    {
    //连接到数据库
    string strCon = @"Integrated Security=SSPI;Packet Size=4096;Data Source=localhost;Tag with column collation when possible=False;Initial Catalog=Book;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=FEI;Use Encryption for Data=False";
    OleDbConnection myConn = new OleDbConnection ( strCon ) ;
    myConn.Open ( ) ;
    string strDele = "DELETE FROM cc_students WHERE stu_no= '" + this.txtNO.Text +"'" ;
    OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
    //从数据库中删除指定记录
    myCommand.ExecuteNonQuery ( ) ;
    //从DataSet中删除指定记录
    this.ccDS.Tables [ "cc_students" ] . Rows [ mybind.Position ] . Delete ( ) ;
    this.ccDS.Tables [ "cc_students" ] . AcceptChanges ( ) ;
    myConn.Close ( ) ;
    }
    catch ( Exception ed )
    {
    MessageBox.Show ( "删除记录错误信息: " + ed.ToString ( ) , "图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information  ) ;
    }
    } private void btnFind_Click(object sender, System.EventArgs e)
    {
    if(this.txtKeyWord.Text == "")
    {
    MessageBox.Show("查询关键字不能为空!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
    return;
    } try
    {
    string sql2;
    sql2 = "SELECT * FROM cc_students WHERE stu_no like '%" + this.txtKeyWord.Text + "%'";
    this.ccDA2 = new System.Data.OleDb.OleDbDataAdapter(sql2,cnn);
    this.ccDS.Clear();
    this.ccDA2.Fill(this.ccDS,"cc_students");
    this.txtKeyWord.Text = "";
    }
    catch (Exception e1)
    {
    MessageBox.Show(e1.Message);
    }
    } private void btnLoad_Click(object sender, System.EventArgs e)
    {
    this.ccDS.Clear();
    this.ccDA.Fill(this.ccDS,"cc_students");
    } private void btnSave_Click(object sender, System.EventArgs e)
    {
    //信息合法性检查
    if (txtNO.Text=="" || txtPrice.Text =="" || txtName.Text=="" || txtCB.Text=="" || txtSort.Text=="")
    {
    MessageBox.Show("提交的信息不完全!","图书管理系统",MessageBoxButtons.OK,MessageBoxIcon.Information );
    return;
    }
    try
    {
    //this.dataGrid1.EndInit();
    //this.mybind.EndCurrentEdit();
    this.ccDA.Update(this.ccDS,"cc_students");
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    } private void btnAdd_Click(object sender, System.EventArgs e)
    {

    } private void btnFirst_Click(object sender, System.EventArgs e)
    {
    this.mybind.Position=0;
    } private void btnLast_Click(object sender, System.EventArgs e)
    {
    this.mybind.Position=mybind.Count-1;
    }