I want to make WebMethod to my WebForms, beforehand this is my function
[WebMethod]
public DataSet GetCustomersData()
{
using(SqlConnection conn = new SqlConnection("MyConnString"))
{
try
{
conn.Open();
string commandstr = "select * from Customers ORDER BY CustomerID";
SqlCommand cmd = new SqlCommand(commandstr, conn);
SqlDataAdapter SqlDa = new SqlDataAdapter(cmd);
DataSet SqlDs = new DataSet();
SqlDa.Fill(SqlDs, "TableCustomer");
if(SqlDs.Tables[0].Rows.Count > 0)
{
return SqlDs;
}
}
catch (SqlException)
{
}
}
}
Actually I want to BindData from WebServices to DataGridView in my WebForm, is there any possible way ?
You should create a POCO class and return a list of this class instead. Dataset contains a lots of aditional data.