DataTable dt = new DataTable();
using (OleDbDataAdapter da = new OleDbDataAdapter(
@"SELECT * FROM F:\myvfp\books.csv",
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\;
Extended Properties=""Text;HDR=No;FMT=Delimited"""))
{
da.Fill(dt);
}
var books = from b in dt.AsEnumerable()
select new
{
Title = b.Field<string>(0),
Publisher = b.Field<string>(1),
Year = b.Field<int>(2)
};
foreach (var book in books)
{
Console.WriteLine(string.Format("Title: {0}, Publisher: {1}, Year: {2}", book.Title, book.Publisher, book.Year));
}
Sunday, January 4, 2009
Saturday, January 3, 2009
Linq with foxpro table
DataTable dt = new DataTable();
using (OleDbDataAdapter da = new OleDbDataAdapter(@"select title as Title, publisher as Publisher, year as Year from books", @"Provider=VFPOLEDB.1;Data Source=c:\myvfp\"))
{
da.Fill(dt);
}
XElement xml = new XElement("books",
dt.AsEnumerable().Where(book =>
book.Field<int>("Year") == 2006)
.Select(book => new XElement("book",
new XAttribute(
"title",
book.Field<string>("Title")),
new XElement(
"publisher",
book.Field<string>("Publisher"))
))
);
Console.WriteLine(xml);
or
XElement xml = new XElement("books",
from book in dt.AsEnumerable()
where book.Field<int>("Year") == 2006
select new XElement("book",
new XAttribute("title", book.Field<string>("Title")),
new XElement("publisher", book.Field<string>("Publisher")
)));
Console.WriteLine(xml);
Instead of
from book in dt.AsEnumerable()
we can use
from DataRow book in dt.Rows
using (OleDbDataAdapter da = new OleDbDataAdapter(@"select title as Title, publisher as Publisher, year as Year from books", @"Provider=VFPOLEDB.1;Data Source=c:\myvfp\"))
{
da.Fill(dt);
}
XElement xml = new XElement("books",
dt.AsEnumerable().Where(book =>
book.Field<int>("Year") == 2006)
.Select(book => new XElement("book",
new XAttribute(
"title",
book.Field<string>("Title")),
new XElement(
"publisher",
book.Field<string>("Publisher"))
))
);
Console.WriteLine(xml);
or
XElement xml = new XElement("books",
from book in dt.AsEnumerable()
where book.Field<int>("Year") == 2006
select new XElement("book",
new XAttribute("title", book.Field<string>("Title")),
new XElement("publisher", book.Field<string>("Publisher")
)));
Console.WriteLine(xml);
Instead of
from book in dt.AsEnumerable()
we can use
from DataRow book in dt.Rows
Wednesday, August 13, 2008
Foxpro Word Automation Replace
The word Macro generates following code to do search and "REPLACE"
With Selection.Find
.Text = "findword"
.Replacement.Text = "replaceword"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
The above will not work in Foxpro, Foxpro use positional parameters
Function Execute([FindText], [MatchCase], [MatchWholeWord], [MatchWildcards], [MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace], [MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]) As Boolean
To use in Foxpro, we have to provide all paramters in right sequence till "ReplaceWith". We can omit rest of the parameters
Const wdFindContinue = 1
oword.Selection.Find.Execute(tcOriginal, .f., .f., .f., .f., .f., .t., wdFindContinue, .f., tcReplace)
With Selection.Find
.Text = "findword"
.Replacement.Text = "replaceword"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
The above will not work in Foxpro, Foxpro use positional parameters
Function Execute([FindText], [MatchCase], [MatchWholeWord], [MatchWildcards], [MatchSoundsLike], [MatchAllWordForms], [Forward], [Wrap], [Format], [ReplaceWith], [Replace], [MatchKashida], [MatchDiacritics], [MatchAlefHamza], [MatchControl]) As Boolean
To use in Foxpro, we have to provide all paramters in right sequence till "ReplaceWith". We can omit rest of the parameters
Const wdFindContinue = 1
oword.Selection.Find.Execute(tcOriginal, .f., .f., .f., .f., .f., .t., wdFindContinue, .f., tcReplace)
Labels:
Foxpro,
Word Automation
Wednesday, August 6, 2008
SYS(987) Foxpro
Foxpro SYS(987) can be used to return remote Varchar data as ANSI for use with Memo fields.
Remote data with varchar fields in foxpro displays square box between each characters

By setting SYS(987, .T.) the data will be in ANSI format.
The above data now displayed as
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
Remote data with varchar fields in foxpro displays square box between each characters

By setting SYS(987, .T.) the data will be in ANSI format.
The above data now displayed as
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
Labels:
Foxpro
Tuesday, July 29, 2008
Open cash register from DOS
type "copy con: open.txt" and press ENTER
press ALT key and hold it
type "27" on your numeric keypad (Numeric Keypad not one above letters )
release ALT key
type "p07y" (small "p" zero seven and small "y"! without quotes)
type Ctrl-z and then Enter
To open the cash register
copy open.txt LPT1:
press ALT key and hold it
type "27" on your numeric keypad (Numeric Keypad not one above letters )
release ALT key
type "p07y" (small "p" zero seven and small "y"! without quotes)
type Ctrl-z and then Enter
To open the cash register
copy open.txt LPT1:
Labels:
Miscellaneous
Wednesday, July 9, 2008
XP SP3 install - Access Denied Error
Windows Update keeps failing on SP3 update with "Access Denied" error. Searching online found this blog.
http://fastest963windows.blogspot.com/2008/05/before-installing-windows-xp-sp3-
access.html
http://fastest963windows.blogspot.com/2008/05/before-installing-windows-xp-sp3-
access.html
Labels:
xp
Friday, June 27, 2008
Generate Create Script from existing table in Foxpro
Generate Create Script from existing table in Foxpro
Following code generates sql create table script for table or cursor in current workspace.
FUNCTION GenerateCreateScript
LPARAMETERS tcCursor
LOCAL ARRAY aa[1]
LOCAL lcAlias, lcCursor, lnFields, lcsql, lcfield, lcType, lnlen, lnDecimal, lnI
lcAlias = ALIAS()
IF EMPTY(lcAlias)
RETURN ''
ENDIF
IF EMPTY(tcCursor) OR VARTYPE(tcCursor) # 'C'
lcCursor = SYS(2015)
ELSE
lcCursor = tcCursor
ENDIF
lnFields = AFIELDS(aa)
lcsql = [ create cursor ] + lcCursor + [ (]
FOR lnI = 1 TO lnFields
lcfield = aa[lni, 1]
lcType = aa[lni, 2]
lnlen = aa[lni, 3]
lnDecimal = aa[lni, 4]
lcsql = lcsql + lcfield + ' ' + lcType + [(] + TRANSFORM(lnlen)
IF lnDecimal > 0
lcsql = lcsql + [,] + TRANSFORM(lnDecimal)
ENDIF
lcsql = lcsql + [)]
IF lnI = lnFields
lcsql = lcsql +[ ;] + CHR(13) + CHR(10) + [)]
ELSE
lcsql = lcsql + [ ;] + CHR(13) + CHR(10) + [, ]
ENDIF
ENDFOR
RETURN lcsql
ENDFUNC
Following code generates sql create table script for table or cursor in current workspace.
FUNCTION GenerateCreateScript
LPARAMETERS tcCursor
LOCAL ARRAY aa[1]
LOCAL lcAlias, lcCursor, lnFields, lcsql, lcfield, lcType, lnlen, lnDecimal, lnI
lcAlias = ALIAS()
IF EMPTY(lcAlias)
RETURN ''
ENDIF
IF EMPTY(tcCursor) OR VARTYPE(tcCursor) # 'C'
lcCursor = SYS(2015)
ELSE
lcCursor = tcCursor
ENDIF
lnFields = AFIELDS(aa)
lcsql = [ create cursor ] + lcCursor + [ (]
FOR lnI = 1 TO lnFields
lcfield = aa[lni, 1]
lcType = aa[lni, 2]
lnlen = aa[lni, 3]
lnDecimal = aa[lni, 4]
lcsql = lcsql + lcfield + ' ' + lcType + [(] + TRANSFORM(lnlen)
IF lnDecimal > 0
lcsql = lcsql + [,] + TRANSFORM(lnDecimal)
ENDIF
lcsql = lcsql + [)]
IF lnI = lnFields
lcsql = lcsql +[ ;] + CHR(13) + CHR(10) + [)]
ELSE
lcsql = lcsql + [ ;] + CHR(13) + CHR(10) + [, ]
ENDIF
ENDFOR
RETURN lcsql
ENDFUNC
Subscribe to:
Posts (Atom)