Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > Problem filling a DataGrid
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 3rd August 12:45
richbrb±Ë¬²*²hœ®‹(~×(
External User
 
Posts: 1
Default Problem filling a DataGrid



Hello,
I can´t fill a DataGrid with a XmlTextReader. I retrieve the quotes for
one AccountId. It worked fine. And then try to put this in a DataGrid thru a
DataSource, but doesn´t work.
It worked great in my develope environment, but in production the page
open blank and nothing happend, no timeout, no error messeges.

My code is:
strColumnSetXml = "<columnset>";
strColumnSetXml += "<column>name</column>";
strColumnSetXml += "<column>statecode</column>";
strColumnSetXml += "<column>totalamount</column>";
strColumnSetXml += "<column>quoteid</column>";
strColumnSetXml += "</columnset>";

Microsoft.Crm.Platform.Proxy.CObjectName objName = new
Microsoft.Crm.Platform.Proxy.CObjectName();
objName.Id = unAccountId;
objName.Type = Microsoft.Crm.Platform.Proxy.ObjectType.otAccount;

int[] arrCodes = new int[]
{Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_DRAFT ,
Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_ACTIVE };
strResultsXml = quote.RetrieveByObject (userAuth, objName, arrCodes,
strColumnSetXml);

XmlTextReader aReader = new XmlTextReader(new StringReader(strResultsXml));
aReader.WhitespaceHandling = WhitespaceHandling.None;

dgQuotes.DataSource = CreateDataSource(aReader);
dgQuotes.DataBind();


The function is:
private ICollection CreateDataSource(XmlTextReader unReader)
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("name", typeof(string)));
dt.Columns.Add(new DataColumn("statecode", typeof(string)));
dt.Columns.Add(new DataColumn("totalamount", typeof(double)));
dt.Columns.Add(new DataColumn("quoteid", typeof(string)));

try
{
while (unReader.Read())
{
if (unReader.HasValue)
{
dr = dt.NewRow();
dr[0] = unReader.Value;
while (!unReader.HasAttributes)
unReader.Read();
dr[1] = unReader.GetAttribute("name");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[2] = unReader.Value.Replace(".", ",");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[3] = unReader.Value;
dt.Rows.Add(dr);
txtHayDatos.Text = "Si";
}

}
Session["Source"] = dt;
DataView dv = new DataView(dt);
return dv;
}
catch (Exception err)
{
// Process other errors here
string strErrorMsg = ("ErrorMessage: " + err.Message );
lblTitulo.Text = strErrorMsg;
return null;
}
}

Thanks!
  Reply With Quote


  sponsored links


2 11th August 16:52
matt parks
External User
 
Posts: 1
Default Problem filling a DataGrid



Rich,

1) Have you tried adding some auditing to make sure you are getting through the
code?

2) Have you checked the html source of hat you are generating to make sure it
looks ok?

3) How about trying loading the XML directly into a dataset instead of using
your own logic? Or using an XML DOM instead of the reader?

The biggest issue I see is that your code is extremely sensitive to the specific
results you are getting back. If it's not formatted exactly as you are
expecting, you will get different results.

Matt Parks
MVP - Microsoft CRM

----------------------------------------
----------------------------------------

Hello,
I can´t fill a DataGrid with a XmlTextReader. I retrieve the quotes for
one AccountId. It worked fine. And then try to put this in a DataGrid thru a
DataSource, but doesn´t work.
It worked great in my develope environment, but in production the page
open blank and nothing happend, no timeout, no error messeges.
My code is:
strColumnSetXml = "<columnset>";
strColumnSetXml += "<column>name</column>";
strColumnSetXml += "<column>statecode</column>";
strColumnSetXml += "<column>totalamount</column>";
strColumnSetXml += "<column>quoteid</column>";
strColumnSetXml += "</columnset>";

Microsoft.Crm.Platform.Proxy.CObjectName objName = new
Microsoft.Crm.Platform.Proxy.CObjectName();
objName.Id = unAccountId;
objName.Type = Microsoft.Crm.Platform.Proxy.ObjectType.otAccount;

int[] arrCodes = new int[]
{Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_DRAFT ,
Microsoft.Crm.Platform.Types.QUOTE_STATE.QS_ACTIVE };
strResultsXml = quote.RetrieveByObject (userAuth, objName, arrCodes,
strColumnSetXml);

XmlTextReader aReader = new XmlTextReader(new StringReader(strResultsXml));
aReader.WhitespaceHandling = WhitespaceHandling.None;

dgQuotes.DataSource = CreateDataSource(aReader);
dgQuotes.DataBind();


The function is:
private ICollection CreateDataSource(XmlTextReader unReader)
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("name", typeof(string)));
dt.Columns.Add(new DataColumn("statecode", typeof(string)));
dt.Columns.Add(new DataColumn("totalamount", typeof(double)));
dt.Columns.Add(new DataColumn("quoteid", typeof(string)));

try
{
while (unReader.Read())
{
if (unReader.HasValue)
{
dr = dt.NewRow();
dr[0] = unReader.Value;
while (!unReader.HasAttributes)
unReader.Read();
dr[1] = unReader.GetAttribute("name");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[2] = unReader.Value.Replace(".", ",");
unReader.Read();
unReader.Read();
while (!unReader.HasValue)
unReader.Read();
dr[3] = unReader.Value;
dt.Rows.Add(dr);
txtHayDatos.Text = "Si";
}

}
Session["Source"] = dt;
DataView dv = new DataView(dt);
return dv;
}
catch (Exception err)
{
// Process other errors here
string strErrorMsg = ("ErrorMessage: " + err.Message );
lblTitulo.Text = strErrorMsg;
return null;
}
}

Thanks!
  Reply With Quote
3 11th August 16:52
richbrb±Ë¬²*²hœ®‹(~×(
External User
 
Posts: 1
Default Problem filling a DataGrid


I changed the way to parse the xml and it works.


while (unReader.Read())
{
switch (unReader.NodeType)
{
case XmlNodeType.Element:
switch (unReader.Name)
{
case "name":
state = iName;
break;
case "statecode":
state = iState;
break;
case "totalamount":
state = iTotal;
break;
case "quoteid":
state = iQuoteId;
break;
}
break;
case XmlNodeType.Text:
switch (state)
{
case iName:
dr[0] = unReader.Value;
state = 0;
break;

ETC...
  Reply With Quote
4 11th August 16:52
richbrb±Ë¬²*²hœ®‹(~×(
External User
 
Posts: 1
Default Problem filling a DataGrid


Thank you Matt,
your perception was correct, my problem was the way I parse the XML. Maybe
the behavior is diferent in diferent environment.

Thanks a lot.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666