2012年3月24日土曜日

Returning a dataset

I am using the Atlas bits that run on the RC build. I thought that there was the capability to return a dataset. Is that working at this point? I am getting a strange error where the local WebDev.WebServer.exe is generating an error and then exiting when I attempt to call a webservice that returns a dataset. The code is pretty simple, so I have included it here just incase I am doing something stupid. I am able to step thru my code, I exit from the method, and then bang I get the error on the terminal. Thoughts? Do I need to change what I am doing? Did I just make up the thought that Datasets were working at this point?
Wally

[WebMethod]

public System.Data.DataSet ReturnDataSet()

{

DataSet ds =newDataSet();

DataTable dt =newDataTable();

DataRow dr;

dt.Columns.Add(newDataColumn("tblStateId", System.Type.GetType("System.Int32")));

dt.Columns.Add(newDataColumn("State", System.Type.GetType("System.String")));

dr = dt.NewRow();

dr["tblStateId"] = 1;

dr["State"] ="Tennessee";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr["tblStateId"] = 2;

dr["State"] ="Alabama";

dt.Rows.Add(dr);

ds.Tables.Add(dt);

return (ds);

}

Interesting. This looks like a bug in Atlas. When I try your code, I get a StackOverflow exception in the serialization process.

Yes, the StackOverflow Exception is what I got also. Sorry fornot being descriptive enough last night. I was a little tired andI am getting the flu. Sad [:(]

I suspect a bug in the DataSetConverter, which is probably caused by circular references between the DataSet and its DataTables.
What you could do for now is to return a DataTable instead (and not use a DataSet at all).

publicoverridestring Serialize(object o)
{
if (!(ois DataSet))
{
thrownew ArgumentException();
}
DataSet set1= (DataSet) o;
StringBuilder builder1=new StringBuilder();
builder1.Append('[');
bool flag1=true;
IEnumerator enumerator1= set1.Tables.GetEnumerator();
try
{
while (enumerator1.MoveNext())
{
DataTable table1= (DataTable) enumerator1.Current;
if (!flag1)
{
builder1.Append(',');
}
builder1.Append(JavaScriptObjectSerializer.Serialize(set1));
flag1=false;
}
}
finally
{
IDisposable disposable1= enumerator1as IDisposable;
if (disposable1 !=null)
{
disposable1.Dispose();
}
}
builder1.Append(']');
return builder1.ToString();
}


Variable table1 wasn't used.
Serialize(set1) rises Stack Overflow exception

0 件のコメント:

コメントを投稿