C# MS Access accdb binding to datagridview WHERE

  • Thread starter Thread starter CSharpNoob2011
  • Start date Start date
C

CSharpNoob2011

Guest
Hi guys,

I am trying to display the details on a DGV based on the ID. The ID is generate from another Datagridview in "DealNumberTxtBox".

If i use this line: I get "Data Type Mismatch in critera expressin"

da = new OleDbDataAdapter("Select * from AllocationTable WHERE Deal_ID = "+ DealID + "", cncl);

However, if i use a number directly, the DGV is loaded. Assuming that the deal that i want to load is the number 7.



da = new OleDbDataAdapter("Select * from AllocationTable WHERE Deal_ID = 7", cncl);


the code:

public void LoadDatagridview()
{
//loading the datagridview from DealTable
string DealID = (DealNumberTxtBox.Text);
//string message = "You did not enter a server name. Cancel this operation?";
string caption = "Data Connection Error";
OleDbConnection cncl = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DealDatabase.accdb;Persist Security Info=False;");
try
{

cncl.Open();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
OleDbDataAdapter da = new OleDbDataAdapter();

da = new OleDbDataAdapter("Select * from AllocationTable WHERE Deal_ID = "+ DealID + "", cncl); //<-- here is the problem.
da.Fill(dt);


AllocdataGridView1.DataSource = dt.DefaultView;
AllocdataGridView1.RowHeadersVisible = false;//hide first column
AllocdataGridView1.AllowUserToAddRows = false; //hide last row
AllocdataGridView1.ReadOnly = true;
AllocdataGridView1.AllowUserToResizeRows = false; //cannot resize row


//setting specifi column as visible




}
catch (Exception a)
{
MessageBox.Show(a.Message, caption);
//cn.Close();
}
finally
{
cncl.Close();
cncl.Dispose();

}


}




I cant get around this.

Can anyone help me out?

Thank you

Cnoob2011


Please do not forget to click “Vote as Helpful” if the reply helps/directs you toward your solution and or "Mark as Answer" if it solves your question. This will help to contribute to the forum.

Continue reading...
 
Back
Top