开发者

Help with LINQ query

I'm trying to retrieve columns based on their corresponding key.

"Select * from diamond where p_Id="+p_Id

I followed MSDN sample and they were doing it like this way:

        CurrencyManager cm = ((CurrencyManager)this.BindingContext[myDatabaseDataSet, "Items.ItemDiamond"]);
        IBindingList list = (IBindingList)cm.List;

but list's related view data only returns data of p_Id=1. What's wrong?.

Full Code:

    private void Viewdiamonds(int p_Id)
    {
        this.Cursor = Cursors.WaitCursor;


        frmDiamond frmd = new frmDiamond();

        CurrencyManager cm = ((CurrencyManager)this.BindingContext[myDatabaseDataSet, "Items.ItemDiamond"]);
        IBindingList list = (IBindingList)cm.List;

        fr开发者_如何学运维md.ShowDialog(p_Id, this, list);

        this.Cursor = Cursors.Default;

    }
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {


        if (e.ColumnIndex == 1 && e.RowIndex != -1 && !dataGridView1.Rows[e.RowIndex].IsNewRow)
        {
            DataGridViewCell cell = this.dataGridView1[e.ColumnIndex - 1, e.RowIndex];
            int p_Id = Convert.ToInt32(cell.Value);
            this.Viewdiamonds(p_Id);

        }
    }

Edit:

I've two related columns, Items and Diamond. I've a datagridview control that display data from Items table. I added a column of type LinkView, so when the user clicks ViewDiamond, a new form pops up and display Diamonds related to that Item. I looked at MSDN DataGridView control sample, and they implemented that using the code above. I did some tweaks to the code to fit my application. What's the wrong with the code above? Because it seems its not able to display the data according to its relative p_Id. Or I think there is somthing wrong with the p_Id, no matter its value, Currency manager seems to retrieve only data corresponed to p_Id = 1.

I hope this clarified the issue.


Never mind, I did it with sql rdr:

        BindingSource bs = new BindingSource();

        string connstring = "Data Source=MyDatabase.sdf;Persist Security Info=False";
        string sqlqry = "SELECT * from diamond where p_Id=" + p_Id;
        SqlCeConnection conn = new SqlCeConnection(connstring);
        SqlCeCommand cmd = new SqlCeCommand(sqlqry, conn);
        conn.Open();

        SqlCeDataReader rdr = cmd.ExecuteReader();
        bs.DataSource = rdr;
        rdr.Close();
        conn.Close();

Whats the equivalent using linq anyway?.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜