Why Dataset is empty?

BenTam 1,801 Reputation points
2024-04-09T09:53:11.9466667+00:00

Dear all,

I am a beginner in C#.

  1. Can you please guide me on how to use parameters?
  2. I am not sure why ds.Table[0] is underlined in red. Could you please assist me in resolving this issue ? RetrieveData
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-04-10T01:28:37.9933333+00:00

    Hi @BenTam-3003 , Welcome to Microsoft Q&A,

    This is an unnecessary and important problem. Also, if you don't need to use the screen, this will be a disadvantage to you.

    When you look at the problem, you don't have to use DataRow in ds.Table[0], and you don't have to use DataRow in ds.Table[0].

    Normal case example:

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand(SelectQuery, connection);
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        DataSet ds = new DataSet();
        adapter.Fill(ds, "Student");
    
        DataTable dt = ds.Tables["Student"];
        if (dt.Rows.Count > 0)
        {
            DataRow r = dt.Rows[0];
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.