Моя проблема в том, что я не могу просмотреть DataSet в форме окна клиента.Я использую метод SetDataBinding, но получаю сообщение об ошибке:
Ошибка : "Systems.Windows.Forms.DataGridView" doesn't contain any defination for SetDataBinding and no extension method accepting first type of argument"
Вот код веб-службы, который возвращает набор данных:
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public DataSet getdata(String rollno)
{
try
{
using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123"))
{
string select = "select * from checkrecord where rollno=@rollno";
SqlDataAdapter da = new SqlDataAdapter(select, myConnection);
DataSet ds = new DataSet();
da.Fill(ds, "students");
return (ds);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
Код на стороне клиента, который связывает данные:
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web.Services;
using System.Web.Services.Protocols;
using WindowsFormsApplication1.dataset1;
//dataset1 is my web reference name
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void calldatagrid_Click(object sender, EventArgs e)
{
Service1 MyService = new Service1();
// Call the GetData method in the Web Service
DataSet ds = MyService.getdata("abc");
// Bind the DataSet to the Grid
datagrid.SetDataBinding=ds;
}
}
}