Hi All, Now see what happen, when export Datate filled with a standard SQL query/stetement:
With this SQL Table:
CREATE TABLE [dbo].[TabExample](
[FieldNvar] [nvarchar](10) NULL,
[FieldInt] [int] NULL,
[FieldDate] [datetime] NULL
) ON [PRIMARY]
GO
With this record #1:
FieldNvar | FieldInt | FieldDate
lwebcode | NULL | 01/01/2017
with standard SQL to fill Dataset we can have some problem:
Dataset ds = ... "SELECT * FROM TabExample"
ds.WriteXml(sTargetXML);
//will return this XML:
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldNvar>lwebcode</FieldNvar>
<FieldDate>2017-01-01T00:00:00+01:00</FieldDate>
</Table>
</NewDataSet>
FieldInt Was Not Write!
With this record #2:
FieldNvar | FieldInt | FieldDate
NULL | 2 | 01/01/2017
with standard SQL to fill Dataset we can have some problem:
Dataset ds = ... "SELECT * FROM TabExample"
ds.WriteXml(sTargetXML);
//will return this XML:
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldInt>2</FieldInt>
<FieldDate>2017-01-01T00:00:00+01:00</FieldDate>
</Table>
</NewDataSet>
FieldNvar Was Not Write!
With this record #3:
FieldNvar | FieldInt | FieldDate
NULL | 2 | NULL
with standard SQL to fill Dataset we can have some problem:
Dataset ds = ... "SELECT * FROM TabExample"
ds.WriteXml(sTargetXML);
//will return this XML
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldInt>2</FieldInt>
<FieldDate>1900-01-01T00:00:00+01:00</FieldDate>
</Table>
</NewDataSet>
If datetime has NULL value it will put firs day of datetime in xml
As in #2 FieldNvar Was Not Write!
To fix this issue, you have to edit SQL Statement using ISNULL Function:
Dataset ds = ... "SELECT ISNULL(FieldNvar, '') FieldNvar, ISNULL(FieldInt, '') FieldInt, ISNULL(FieldDate , '') FieldDate FROM TabExample"
with record #1, we have a error on converting Numeric Value to char, see later what to do.
with record #2
XML file will like:
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldNvar/>
<FieldInt>2</FieldInt>
<FieldDate>2017-01-01T00:00:00+01:00</FieldDate>
</Table>
</NewDataSet>
with record #3
XML file will like:
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldNvar/>
<FieldInt>2</FieldInt>
<FieldDate/>
</Table>
</NewDataSet>
with record #1 there is a last thing to do on all numeric value (int, decimal etc...), in SQL you neet to put ISNULL function with CAST our SQL query will Like:
Dataset ds = ... "SELECT ISNULL(FieldNvar, '') FieldNvar, CASE WHEN FieldInt IS NULL THEN '' ELSE CAST(FieldInt AS NVARCHAR(50)) END FieldInt, ISNULL(FieldDate , '') FieldDate FROM TabExample"
Now XML file will like:
<?xml version="1.0" standalone="true"?>
<NewDataSet>
<Table>
<FieldNvar>lwebcode</FieldNvar>
<FieldInt/>
<FieldDate>2017-01-01T00:00:00+01:00</FieldDate>
</Table>
</NewDataSet>
With this fix in sql statement, we can export every kind of fields and be sure that each field will be write on xml file.
Showing posts with label dynamic. Show all posts
Showing posts with label dynamic. Show all posts
Tuesday, 7 February 2017
C# Export Dataset To XML, ISNULL Exporting fix
Labels:
c#,
Database,
debugging,
dynamic,
ExecuteNonQuery,
ExecuteReader,
ExecuteScalar,
Field,
Fix,
Framework,
lwebcode,
Microsoft SQL Server,
MSSQL,
Runtime,
Script,
SQL,
SqlConnection,
structure,
Table
Wednesday, 25 January 2017
C# CSS Stylesheet Compression, fast website loading
Hi All, Here's a static class developed in c# to compress Css stylesheets,
It removes all “\r\n” (newline carriage return) , all “\t” (tab) all spaces before and after “:” “;” , it also remove all comment from your css.
Thanks to this function Stylesheet should be more light and fast for web and you can remove additionals spaces manually for complete optimization .
You can copy your css and pass it to class with:
textBox2.Text = LWEBCODE.Get_CSS_RTM(textBox1.Text);
I suggest to make a form o webform with 2 textboxes and paste in textbox1 your css stylesheet ,result can be show in textbox2 , after paste into css_runtime_sheet.css,
REMEMBER on pagae_load event or in <head> tag to correctly set the right stylesheet: version for development and debug, or runtime version
Please for any optimization or suggestion contact us.
Here the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
/*
Css Runtime Generator, compressor
developed by: lwebcode;
for other script and resource :
http://lwebcode.blogspot.com/
*/
class LWEBCODE
{
public static string Get_CSS_RTM(string sInpunt)
{
string sOut = "";
char[] c = System.Environment.NewLine.ToCharArray();
string[] sRows = new string[] { };
string[] sRow = new string[] { };
bool Esc1 = false;
bool Esc2 = false;
bool Esc3 = false;
sRows = Regex.Split(sInpunt, "\t");
for (int i = 0; i 0)
{
if (sRows[i].IndexOf(Convert.ToChar("-")) < 0)
{
sRows[i] = sRows[i].Trim();
}
}
sRow = SplitChar(sRows[i]);
for (int j = 0; j < sRow.Length; j++)
{
if (sRow[j] == "/")
{
if (j < sRow.Length - 1)
{
if (sRow[j + 1] == "*")
{
Esc1 = true;
}
}
}
if (sRow[j] == "*")
{
if (j < sRow.Length - 1)
{
if (sRow[j + 1] == "/")
{
Esc1 = false;
j = j + 2;
}
}
}
if (j < sRow.Length)
{
char[] c2 = sRow[j].ToCharArray();
if ((c[0] == c2[0]) || (c[1] == c2[0]))
Esc2 = true;
else
Esc2 = false;
}
if (j < sRow.Length)
{
char[] c2 = sRow[j].ToCharArray();
if (c2[0] == Convert.ToChar(" "))
{
if ((sRow[j - 1] == ":") || (sRow[j - 1] == ";"))
Esc3 = true;
else
Esc3 = false;
if ((j + 1 < sRow.Length) && (!Esc3))
{
if ((sRow[j + 1] == ":") || (sRow[j + 1] == ";"))
Esc3 = true;
else
Esc3 = false;
}
}
else
{
Esc3 = false;
}
}
if ((!Esc1) && (!Esc2) && (!Esc3))
{
if (j <= sRow.Length - 1)
{
sOut += sRow[j];
}
}
}
return sOut;
}
private static string[] SplitChar(string sIn)
{
string[] sInSpl;
sInSpl = new string[sIn.Length];
for (int i = 0; i < sIn.Length; i++)
{
sInSpl[i] = sIn.Substring(i, 1);
}
return sInSpl;
}
}
It removes all “\r\n” (newline carriage return) , all “\t” (tab) all spaces before and after “:” “;” , it also remove all comment from your css.
Thanks to this function Stylesheet should be more light and fast for web and you can remove additionals spaces manually for complete optimization .
You can copy your css and pass it to class with:
textBox2.Text = LWEBCODE.Get_CSS_RTM(textBox1.Text);
I suggest to make a form o webform with 2 textboxes and paste in textbox1 your css stylesheet ,result can be show in textbox2 , after paste into css_runtime_sheet.css,
REMEMBER on pagae_load event or in <head> tag to correctly set the right stylesheet: version for development and debug, or runtime version
Please for any optimization or suggestion contact us.
Here the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
/*
Css Runtime Generator, compressor
developed by: lwebcode;
for other script and resource :
http://lwebcode.blogspot.com/
*/
class LWEBCODE
{
public static string Get_CSS_RTM(string sInpunt)
{
string sOut = "";
char[] c = System.Environment.NewLine.ToCharArray();
string[] sRows = new string[] { };
string[] sRow = new string[] { };
bool Esc1 = false;
bool Esc2 = false;
bool Esc3 = false;
sRows = Regex.Split(sInpunt, "\t");
for (int i = 0; i 0)
{
if (sRows[i].IndexOf(Convert.ToChar("-")) < 0)
{
sRows[i] = sRows[i].Trim();
}
}
sRow = SplitChar(sRows[i]);
for (int j = 0; j < sRow.Length; j++)
{
if (sRow[j] == "/")
{
if (j < sRow.Length - 1)
{
if (sRow[j + 1] == "*")
{
Esc1 = true;
}
}
}
if (sRow[j] == "*")
{
if (j < sRow.Length - 1)
{
if (sRow[j + 1] == "/")
{
Esc1 = false;
j = j + 2;
}
}
}
if (j < sRow.Length)
{
char[] c2 = sRow[j].ToCharArray();
if ((c[0] == c2[0]) || (c[1] == c2[0]))
Esc2 = true;
else
Esc2 = false;
}
if (j < sRow.Length)
{
char[] c2 = sRow[j].ToCharArray();
if (c2[0] == Convert.ToChar(" "))
{
if ((sRow[j - 1] == ":") || (sRow[j - 1] == ";"))
Esc3 = true;
else
Esc3 = false;
if ((j + 1 < sRow.Length) && (!Esc3))
{
if ((sRow[j + 1] == ":") || (sRow[j + 1] == ";"))
Esc3 = true;
else
Esc3 = false;
}
}
else
{
Esc3 = false;
}
}
if ((!Esc1) && (!Esc2) && (!Esc3))
{
if (j <= sRow.Length - 1)
{
sOut += sRow[j];
}
}
}
return sOut;
}
private static string[] SplitChar(string sIn)
{
string[] sInSpl;
sInSpl = new string[sIn.Length];
for (int i = 0; i < sIn.Length; i++)
{
sInSpl[i] = sIn.Substring(i, 1);
}
return sInSpl;
}
}
Tuesday, 24 January 2017
SQL Dynamic table’s name in SELECT COUNT(*),TOP 1, MAX etc..
Hi All, here a easy lwebcode's sql script, to make a SELECT COUNT(*), or other sql statements wich return only 1 result (SELECT TOP 1, SELECT MAX, etc..) with dynamic tables name and put in a parameter o variable,
It works well in All Sql Server versions, from MS SQL Server 2000 to last SQL Server 2016
--LWEBCODE SQL SCRIPT Dynamic table's name
It works well in All Sql Server versions, from MS SQL Server 2000 to last SQL Server 2016
--LWEBCODE SQL SCRIPT Dynamic table's name
Declare @tableName varchar(100),
@tableCount int,
@sql nvarchar(100)
Set @tableName = 'Products'
Set @sql = N'Select @tableCount = Count(*) from ' + @tableName
exec sp_executesql @sql, N'@tableCount int output', @tableCount output
Select @tableCount
Subscribe to:
Posts (Atom)