Hi,
You can use threading in webservice to insert data in one webmethod , which will make that method to run process in background.
And using another method you can get data
Two webmethods are as below...
[WebMethod]
public void InsertData()
{
Thread myThread = new Thread(StartThread1);
myThread.Start();
}
[WebMethod]
public DataSet Getdata()
{
SqlConnection myconn = new SqlConnection();
myconn.ConnectionString = "Data Source=Demo-PC\\SQLEXP1;Initial Catalog=DB1;User ID=sa;Password=******";
string strsql = "select * from Table2";
SqlCommand cmd = new SqlCommand(strsql, myconn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public void StartThread1()
{
SqlConnection myconn = new SqlConnection();
myconn.ConnectionString = "Data Source=Demo-PC\\SQLEXP1;Initial Catalog=DB1;User ID=sa;Password=*******";
myconn.Open();
string strsql = "insert into Table2 values(2,'test1')";
SqlCommand cmd = new SqlCommand(strsql, myconn);
cmd.ExecuteNonQuery();
strsql = "insert into Table2 values(2,'test1')";
cmd = new SqlCommand(strsql, myconn);
cmd.ExecuteNonQuery();
strsql = "insert into Table2 values(2,'test1')";
cmd = new SqlCommand(strsql, myconn);
cmd.ExecuteNonQuery();
}
Call webmethods as from your page ......
Data objdata = new Data();
InsertData();
Thread.Sleep(2000);
DataSet ds = new DataSet();
ds = objdata.Getdata();
public void InsertData()
{
Data objdata = new Data();
objdata.InsertData();
}
----------------------------
Hope this can help you
let me know if have any question or need more help