Hi @Elado ,
I run and test your codes and maybe I have found your problem. What 's your Products:
dataset.Tables["Products"]
I think you need to add a name when you do the fill operatation:
public static DataTable GetProducts()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand command;
try
{
conn.Open();
command = new SqlCommand("SELECT * FROM Test", conn);
adapter.SelectCommand = command;
DataSet dataset = new DataSet();
adapter.Fill(dataset, "Products"); // add a name
if (dataset.Tables["Products"].Rows.Count != 0)
{
return dataset.Tables["Products"];
}
return null;
}
catch (Exception e)
{
return null;
}
finally
{
if (conn != null && conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
Best regards,
Yijing Sun
If the answer is helpful, please click "Accept Answer" and upvote it.
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.