I have a query that selects 3 columns from a SQL table, I need to export the resulting query into a listview. I don’t need any help with the SQL setup, just how to format it into the listview. There is where I am stuck. Any help is appreciated. Thanks!
string sql = "select distinct pro,ds,date from dbo.Sge where date IN (select max(date) from dbo.Storage) order by project";
SqlConnection con = new SqlConnection("Data Source= ;Initial Catalog= ;Integrated Security= SSPI");
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql,con);
adapter.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
for(int i=0; i< ds.Tables[0].Columns.Count; i++))
}
Edit: Sorry guys, i mentioned ListBox originally and i meant ListView. My ListView is detailed and had a column for each of my columns in my select, i just simply need the SQL export to go to the right column.
This is what I have come up with, but it doesn’t add to each column, just to the first column
foreach (DataRow row in poplb6ds.Tables[0].Rows)
{
listView1.Items.Add(row["Pro"].ToString());
listView1.Items.Add(row["size"].ToString());
listView1.Items.Add(row["Date"].ToString());
}
The following assumes that your ListView has columns in the order |Pro|Size|Date|