简体   繁体   中英

how to retrive data from the database based on a value of the cell of the datagridview

我有一个datagridview,它显示客户详细信息列表,例如客户ID,姓名等。当我单击特定客户行然后单击按钮时,我希望该客户的客户ID存储在字符串中,然后将使用MySQL命令来检索客户的菜单选项。例如,从菜单中选择*,其中customerid =(从datagridview获得的字符串)

Try this

private void button1_Click(object sender, EventArgs e)
{
    if (dataGridView1.SelectedCells.Count > 0)
    {
        int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
        DataGridViewRow selectedRow = datagridview1.Rows[selectedrowindex];  
        string CustumerID = Convert.ToString(selectedRow.Cells["column name"].Value);           
    }
}

or this

private void button1_Click(object sender, EventArgs e)
{
    int SelectedRowndex = dataGridView1.CurrentCell.RowIndex;
    string CustumerID= dataGridView1.Rows[SelectedRowndex].Cells["column name"].Value.ToString();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM