c#
  • winforms
  • ms-access
  • 2011-04-11 94 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

    相關問題