Reply to thread

I am trying to retrieve data from SQL Server to a DataTable object:



//It doesn't really relevant to the question, so you can skip reading this function


 public static DataTable FillByMail(string Email)

        {

            const string SQL_SP = "dbo.usp_MySP ";

            DataTable results = new DataTable();

            try

            {

                SqlConnection con = new SqlConnection(ConnectionString);

                SqlDataAdapter da = new SqlDataAdapter(SQL_SP, con);

                da.SelectCommand.CommandType = CommandType.StoredProcedure;

                da.SelectCommand.Parameters.Add("@email", SqlDbType.VarChar, 320).Value = Email;

                da.Fill(results);

            }

            catch { }

                return results;

        }



The Stored Procedure I am calling is returning multiple rows of 4 columns:


  1. ProjectID (int)
  2. Project (varbinary)
  3. CreationDate (datetime)
  4. ProjectName (varchar)


I am trying to populate a ListBox named "OnlineProjects" using the returned DataTable. I plan to have the "ProjectName" as the Name and a tuple of "ProjectID", "Project" and "CreationDate" as the value. But the problem is I don't know how to retrieve that data from the DataTable and how to use the retrieved data to populate the ListBox. How can it be done? please note that the DataTable can change over time so if it possible for the ListBox to change with it (Like in .DataSource) it would be great.


Thank you in advance!


Continue reading...


Back
Top