how can i normally select table/column in inner join query?
look at this code SQL CODE HERE
this is how i populate my dgv
SqlConnection con = new SqlConnection("Data Source=DESKTOP-5V9PS33\\SQLEXPRESS;Initial Catalog=Farmacia;Integrated Security=True");
con.Open();
SqlCommand sc = new SqlCommand("SELECT Category,Subcategory,Product,Supplier FROM Inventory Inner Join Category ON Category.ID = Inventory.CategoryID Inner Join Subcategory ON Subcategory.ID = Inventory.SubcategoryID Inner Join Product ON Product.ID = Inventory.ProductID Inner Join Supplier ON Supplier.ID = Inventory.SupplierID", con);
SqlDataReader reader;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Product", typeof(string));
dt.Columns.Add("Category", typeof(string));
dt.Columns.Add("Subcategory", typeof(string));
dt.Columns.Add("Supplier", typeof(string));
dt.Load(reader);
for (int x = 0; x < dt.Rows.Count; x++)
{
string ID = dt.Rows[x].ItemArray[0].ToString();
string Product = dt.Rows[x].ItemArray[1].ToString();
string Category = dt.Rows[x].ItemArray[2].ToString();
string Subcategory = dt.Rows[x].ItemArray[3].ToString();
string Supplier = dt.Rows[x].ItemArray[4].ToString();
string[] row = { ID,Product, Category, Subcategory, Supplier };
dgvInventory.Rows.Add(row);
}
i need to output the ID together with the other information in one query so i can put them into one datatable then populate the DGV with it
将Inventory.Id
添加到您select
查询中。
SELECT Inventory.Id, Category,Subcategory,Product,Supplier FROM Inventory ...
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.