Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting into Foxpro date field
Message
From
17/01/2007 22:48:40
 
 
To
17/01/2007 06:15:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01185949
Message ID:
01186507
Views:
27
Thanks Cetin.
Your code sample was very helpful.
Thanks again.


>>Hello.
>>
>>I'm trying to insert a row into a foxpro table.
>>When inserting a date value into a foxpro table, what must I convert the value to before I can do an insert?
>>
>>I've tried this (and various combo of others)
>>
>>dDel_date =DateTime.Parse(TRow["del_date"].ToString().Trim()).Date
>>
>>and it didn't work.
>>
>>
>>TIA.
>
>Sam,
>Are you converting and parsing to get a date from a date?
>Use parameters in select/update/insert/delete. ie: Below code creates a free table in c:\temp and inserts some values in it.
>*Corresponding VFP code:
>
>create table ("c:\temp\myNewTable") (f1 i, f2 c(20), f3 d)
>for i=0 to 4
> insert into myNewTable (f1,f2,f3) values (m.i*5,"TestRecord #"+ltrim(str(m.i)),Date()+m.i)
>endfor
>use
>
>
>C#:
>
>using System;
>using System.Data;
>using System.Data.OleDb;
>class test
>{
> static void Main()
> {
>   string strCon = @"Provider=VFPOLEDB;Data Source=c:\temp\";
>   OleDbConnection cn = new OleDbConnection(strCon) ;
>   cn.Open();
>   OleDbCommand cmdCreateTable =
>       new OleDbCommand("create table myNewTable (f1 i, f2 c(20), f3 d)",cn);
>   cmdCreateTable.ExecuteNonQuery();
>
>     string strInsert = "insert into myNewTable (f1,f2,f3) values (?,?,?)";
>
>     // Prepare command and parameters
>     OleDbCommand cmd = new OleDbCommand(strInsert,cn);
>     OleDbParameter f1 = cmd.Parameters.Add("parm1",OleDbType.Integer);
>     OleDbParameter f2 = cmd.Parameters.Add("parm2",OleDbType.Char);
>     OleDbParameter f3 = cmd.Parameters.Add("parm3",OleDbType.Date);
>
>     // insert 5 records
>     for (int i=0;i<5;i++)
>     {
>     	f1.Value = i*5;
>     	f2.Value = String.Format("TestRecord #{0}",i);
>     	f3.Value = DateTime.Now.AddDays(i);
>        cmd.ExecuteNonQuery();
>     }
>     cn.Close();
> }
>}
>
Cetin
The American Republic will endure, until politicians realize they can bribe the people with their own money.
- Alexis de Tocqueville

No man’s life, liberty, or property is safe while the legislature is in session.
– Mark Twain (1866)
Previous
Reply
Map
View

Click here to load this message in the networking platform