Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

C# MS Access accdb binding to datagridview WHERE

$
0
0

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 can't 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.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>