Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dataset.GetXML() method doesn't Return Null Values. Any Solution?

Reply
Thread Tools

Dataset.GetXML() method doesn't Return Null Values. Any Solution?

 
 
Nanda
Guest
Posts: n/a
 
      11-29-2005
Hi All,

Thanks for u r Valuable postings.
Here is a Problem for me.

I need to reprsent the NULL value of a column in Database in an XML
File as follows.

<Employees>
<Employee>
<Name>John</Name>
</Addr>
<City>NewYork</City>
</Employee>
</Employees>

Here </Addr> represents a null field in Database.
But using Dataset.GetXML() method I am getting the XML O/p as follows.
<Employees>
<Employee>
<Name>John</Name>
<City>NewYork</City>
</Employee>
</Employees>

Can Any body help me from this situation?
Thanks in Advance
Regards
Nanda

 
Reply With Quote
 
 
 
 
Kalpesh
Guest
Posts: n/a
 
      11-29-2005
Hi,

This is because it is containing NULL (DBNull.Value) - it is being
ignored.
Maybe, you can traverse for column having DBNull.Value & make it blank

Then, I guess it should emit XML the way you want

HTH
Kalpesh

 
Reply With Quote
 
 
 
 
Mohit_Aren Mohit_Aren is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-01-2008
private void setNullToDefVals(ref DataSet dsXML)
{
try
{
if(dsXML.Tables.Count > 0)
{
for(int index = 0; index < dsXML.Tables.Count; index++)
{
if(dsXML.Tables[index].Rows.Count > 0)
{
for(int rindex= 0; rindex < dsXML.Tables[index].Rows.Count; rindex++)
{
for(int cindex=0; cindex < dsXML.Tables[index].Columns.Count; cindex++)
{
if(dsXML.Tables[index].Rows[rindex][cindex] == System.DBNull.Value)
{
DateTime defdate = new DateTime(2000,1,1);
if(dsXML.Tables[index].Columns[cindex].DataType == System.Type.GetType("System.String"))
dsXML.Tables[index].Rows[rindex][cindex] = "";
else if(dsXML.Tables[index].Columns[cindex].DataType == System.Type.GetType("System.Int32"))
dsXML.Tables[index].Rows[rindex][cindex] = 0;
else if(dsXML.Tables[index].Columns[cindex].DataType == System.Type.GetType("System.DateTime"))
dsXML.Tables[index].Rows[rindex][cindex] = defdate;
else if(dsXML.Tables[index].Columns[cindex].DataType == System.Type.GetType("System.Decimal"))
dsXML.Tables[index].Rows[rindex][cindex] = 0.0;
else
{
// dsXML.Tables[index].Columns[cindex].DataType = System.Type.GetType("System.String");
// dsXML.Tables[index].Rows[rindex][cindex] = "";
}
}
}
}
}
}
}
}
catch(Exception ex)
{
int i =0;
}
}
 
Reply With Quote
 
Mohit_Aren Mohit_Aren is offline
Junior Member
Join Date: May 2008
Posts: 2
 
      05-20-2008
Can also use this function before adding default values to get only valuesless tags:

private void createVarcharColumns(ref DataSet dsXML)
{
try
{
if (dsXML.Tables.Count > 0)
{
for (int index = 0; index < dsXML.Tables.Count; index++)
{
if (dsXML.Tables[index].Rows.Count > 0)
{
for (int cindex = 0; cindex < dsXML.Tables[index].Columns.Count; cindex++)
{
if (dsXML.Tables[index].Columns[cindex].DataType != System.Type.GetType("System.String"))
{
string oldColName = dsXML.Tables[index].Columns[cindex].ColumnName;
if (oldColName != "LOCATIONID" && oldColName != "SUBLOCATIONID")
{
DataColumn objColmn = new DataColumn(dsXML.Tables[index].Columns[cindex].ColumnName + "Def", System.Type.GetType("System.String"));
dsXML.Tables[index].Columns.Add(objColmn);
string newColName = objColmn.ColumnName;
int newcindex = getColumnIndex(dsXML.Tables[index], newColName);
for (int rindex = 0; rindex < dsXML.Tables[index].Rows.Count; rindex++)
{
if (dsXML.Tables[index].Rows[rindex][cindex] == System.DBNull.Value)
{
dsXML.Tables[index].Rows[rindex][newcindex] = "";
}
else
dsXML.Tables[index].Rows[rindex][newcindex] = dsXML.Tables[index].Rows[rindex][cindex].ToString();
}
dsXML.Tables[index].Columns.Remove(dsXML.Tables[index].Columns[cindex].ColumnName);
newcindex = getColumnIndex(dsXML.Tables[index], newColName);
dsXML.Tables[index].Columns[newcindex].ColumnName = oldColName;
cindex--;
}
}
}
}
}
}
}
catch (Exception ex)
{
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can realloc(p,0) return NULL when p is non-NULL and memory aplenty? Francois Grieu C Programming 14 03-07-2008 05:40 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
Why use "return (null);" instead of "return null;" ? Carl Java 21 08-24-2006 04:33 AM
Cannot invoke Call with null namespace URI for method null raviupasi@gmail.com Java 0 05-12-2006 01:34 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM



Advertisments