Here is my asp.net code:
public static void GetInvoices(int client_id)
{
using ( var conn = new SqlConnection( GetConnectionString() ) )
using ( var cmd = conn.CreateCommand() )
{
conn.Open();
cmd.CommandText =
conn.Open();
cmd.CommandText =
@"SELECT o.OrderID, o.OrderDate, o.Status, o.ShipDate, o.PostAmount, sum(p.PaymentAmt) as Paid
FROM Orders o left outer join payment p on o.orderid = p.orderid WHERE o.DistID = @client_id
Group by o.OrderID, o.OrderDate, o.Status, o.ShipDate, o.PostAmount
Order By o.OrderDate Desc";
cmd.Parameters.AddWithValue( "@client_id", client_id );
cmd.ExecuteNonQuery();;
}
}
How can I attach the information returned from this (which could possible be 0 rows returned) to a ListView control?
Is it as easy as
ListViewInvoices.DataSource = GetInvoices(1);
ListViewInvoices.DataBind();
Or is there a more involved to connect it to a sql query data set?
As you can see GetInvoices is a void method; returns nothing. You will need to use DataAdapter to fill and return a DataTable or DataSet. Then the last two lines should work