Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Below is the code i am using to fill the dt from the web service

C#
PASSBOOK.svcPB.ServiceSoapClient accdetails=new PASSBOOK.svcPB.ServiceSoapClient();
dt = accdetails.GetAccountDetails(txtaccountnum.Text);


Please let me know if there is any other methods to do the same.

Thank you
Posted

1 solution

Since I don't have your service, I had to create sample data, but I think the following code fragment shows the basic idea.

// structure for sample data
struct SampleRec { public string caption; public int val; };

// data provider like your service method
static List<SampleRec> ServiceMock()
{
    return new List<SampleRec>() {
        new SampleRec() { caption = "test1", val = 1 },
        new SampleRec() { caption = "test2", val = 2 }};
}

// fill a data grid with sample data
private void buttonFill_Click(object sender, EventArgs e)
{
    // create a test table
    var dt = new System.Data.DataTable();
    dt.Columns.Add("caption", typeof(string));
    dt.Columns.Add("value", typeof(int));

    dt.BeginLoadData();
    // sample data
    // change following part with the service data
    ServiceMock().ForEach(r1 =>
    {
        dt.LoadDataRow(new object[] { r1.caption, r1.val }, LoadOption.OverwriteChanges);
    });

    dt.EndLoadData();
    this.dataGridView1.DataSource = dt;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900