I have two tables in my database Category (Cat_id, Cat_name) and Products. Cat_id is a foreign key in the Products table.
When I retrieve product details from the Products table into a DataGridView, I want to show Cat_id column's value with its name (by Cat_name) not id itself.
How do I do that? Please help me. Below is a sample code.
private void searchIconPIctureBox_Click(object sender, EventArgs e)
{
string product_txt = searchTxt.Text;
if ((product_txt) != "")
{
try
{
conn.Open();
com.Connection = conn;
string search_Product = searchTxt.Text;
com.CommandText = "select Name, Type, Amount, Price, Cat_id from Product_records where Name = search_Product ";
SqlDataReader dtr = com.ExecuteReader();
DataTable dttable = new DataTable();
dttable.Load(dtr);
ProductGridView.DataSource = dttable;
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}