0

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?

2
  • Did you try those last two lines? Commented Apr 27, 2012 at 21:12
  • I did not because it just didn't make sense in my mind. Then I got pulled off on something else, will still have to come back to this just couldn't test those last two lines at the moment. Commented Apr 27, 2012 at 21:20

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Alright that makes sense. I will add that and test it as soon as I can get to it.
OK. May be instead of last two lines probably you will need to iterate through the DataTable and construct ListViewItems and add to the list view.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.