Reputation: 5150
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?
Upvotes: 0
Views: 343
Reputation: 3297
GetInvoices don't return neither DataSet nor DataTable, you're just executing the query but don't get the returned data in DataContainer aka DataSet or DataTable.
Upvotes: 0
Reputation: 4361
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
Upvotes: 1