c#
  • winforms
  • ms-access
  • 2011-04-11 96 views -1 likes 
    -1

    如何在C#Windows窗体应用程序中搜索Microsoft Access记录?在C#Windows窗体应用程序中搜索Microsoft Access记录?

    代码:

    private void btnsearch_Click(object sender, EventArgs e) 
        { 
         dataAdapter = new OleDbDataAdapter("SELECT * from tblStudents WHERE studid='" + 
                  txtstudid.Text + "' ", 
                  conn); 
         dataset = new DataSet(); 
    
         dataAdapter.Fill(dataset); 
         dataGridView1.DataSource = dataset.Tables[0]; 
        } 
    
    +0

    您应该在每行之前放置四个空格来格式化代码。您也可以选择它并单击“{}”按钮。在[Markdown编辑帮助](http://stackoverflow.com/editing-help)页面提供更多有用的提示。另外,告诉我们什么是错的。如果我们不知道您需要什么帮助,我们无法帮助您。 – 2011-04-11 17:24:22

    +0

    我编辑了你的问题,以便代码块可读。即使这样,我也搞不清楚你在问什么。你能澄清吗? – 2011-04-11 17:25:38

    +0

    我希望搜索记录和搜索记录显示在datagridview中 – rajashekhar 2011-04-11 17:47:31

    回答

    0
    //BindingSource to sync DataTable and DataGridView 
    BindingSource bSource = new BindingSource(); 
    
    //set the BindingSource DataSource 
    bSource.DataSource = ds.Tables[0]; 
    
    //set the DataGridView DataSource 
    dataGridView1.DataSource = bSource; 
    

    要得到改变回数据库,所有你需要做的就是与DataTable调用OleDbDataAdapterUpdate()为做到这一点的说法。

    da.Update(ds.Tables[0]); 
    
    +0

    运行时,它显示da.Fill(ds)中的错误(错误:OleDbException未处理) – rajashekhar 2011-04-11 18:08:18

    +0

    您的ConnectionString是否正确初始化? – 2011-04-11 18:31:04

    相关问题