Reputation: 693
I have a datagrid I am trying to populate with my query. The code below works in my winform app and I didn't think that asp and c# binding data would be that different. I have seen people use Dataset and SqlCommand but it didn't seem relevant since it worked in my winform app. How can I change this to work for ASP gridview? Thank you for your time and help.
Method for getting the data: It should return two columns of data.
StringBuilder sqlString = new StringBuilder();
sqlString.Append("SELECT DISTINCT o.SALES_NUMBER AS [Sales Number], ");
sqlString.Append("d.DropTime AS [Drop Time] ");
sqlString.Append("FROM [L\\sqlexpress].F_MSS.dbo.Order_Detail o ");
sqlString.Append("FULL OUTER JOIN ");
sqlString.Append("[COMMAND\\sqlexpress].Practiceville.dbo.DropTime d ");
sqlString.Append("ON o.SALES_NUMBER = d.SalesONumber ");
sqlString.Append("Where o.SALES_NUMBER IS NOT NULL ");
sqlString.Append("Order by o.SALES_NUMBER ");
DataTable dt = null;
SqlConnection dbConn = new SqlConnection(Properties.Settings.Default["Connection"].ToString());
try
{//set data source
dt = DBHelper.executeDataTable(dbConn, sqlString.ToString(), null);
if (dt != null)
{
dropGridView.DataSource = dt;
}
dbConn.Close();
dbConn.Dispose();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dbConn != null)
{
try { dbConn.Close(); dbConn.Dispose(); }
catch { }
}
}
Upvotes: 0
Views: 504
Reputation: 7943
You need to DataBind:
dropGridView.DataSource = dt;
dropGridView.DataBind();
Upvotes: 2