私の問題は、クライアント側のWindowsフォームでDataSetを表示できないことです。
SetDataBindingメソッドを使用していますが、次のようなエラーが表示されます。
Error:
"Systems.Windows.Forms.DataGridView" doesn't contain any
defination for SetDataBinding and no extension method accepting
first type of argument"
データセットを返すWebサービスコードは次のとおりです。
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 [email protected]
データをバインドするクライアントサイドのコード:
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;
}
}
}
ベストアンサー
SetDataBindingはDataGrid(DataGridViewではなく)で定義され、プロパティではないメソッドであり、2つのパラメータが必要です。代わりにお試しください:
datagrid.DataSource = ds;
オプションで:
datagrid.DataMember = "TableName";
脇に...データセットは、Webサービスにとって恐ろしい恐ろしい選択です。