How can i save a date from vb.net to a dbf file?

  • Thread starter Ivan V via DotNetMonster.com
  • Start date
I

Ivan V via DotNetMonster.com

Dear All:

I got a serious problem in updating the date field from vb.net to abd dbf
file. My code is as follow:

Dim ConnectionString As String

Dim cake As Date = Date.Parse(idate)

Console.WriteLine(Format(cake, "MM/dd/yyyy"))

ConnectionString = "Provider=vfpoledb;Data Source=g:\project\
cashier\data\cashier.dbc;" & _
"Mode=ReadWrite|Share Deny None;" & _
"Collating Sequence=MACHINE;" & _
"Password=''"

Dim dBaseConnection As New System.Data.OleDb.OleDbConnection
(ConnectionString)
dBaseConnection.Open()

Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("update
caslip set ref_no = " & "'" & ref.Text$ & "'" & _
" ," & "inv_amt = " & CDec(inv_amt.Text) & _
" ," & "inv_dt = " & "'" & (cake) & "'" & _
" ," & "pro_no = " & "'" & f_no & "'" & _
" ," & "dep_no = " & "'" & d_no & "'" & _
" ," & "can_ind = " & p_tick & _
" ," & "cus_code = " & "'" & ser.Text & "'"
& _
" ," & "cash_amt = " & CDec(cash.Text) & _
" ," & "c_amt = " & CDec(c_card.Text) & _
" ," & "ent_amt = " & CDec(ent.Text) & _
" ," & "c_code = " & "'" & type.Text & "'" &
_
" ," & "c_chg = " & CDec(o_chr.Text) & _
" ," & "hou_amt = " & CDec(h_use.Text) & _
" ," & "remark = " & "'" & rmk.Text & "'" &
_
" ," & "oth_amt = " & CDec(other.Text) & _
" ," & "net_amt = " & CDec(dep_amount.Text)
& _
" ," & "dis_amt = " & CDec(discount.Text) &
_
" ," & "doc_no = " & "'" & ofi_no.Text & "'"
& _
" ," & "doc_dt = " & "'" & dt.Text & "'" & _
" where inv_no = " & "'" & think & "'",
dBaseConnection)
Dim vr As System.Data.OleDb.OleDbDataReader = dBaseCommand.
ExecuteReader(CommandBehavior.CloseConnection)

dBaseConnection.Close()
vr.Close()


this coding works fine on every part except when i put in the date filed, it
gave me the error message "Data Type Mismatch". I did test every single field
from the code, and I realized that it's the date format problem. Anyone has a
solution on that?? Thanks for the help!!~
 
C

CT

It's been a long time since I played with VFP, but I believe you can use the
strict date format, {^YYYY/MM/DD}
 
C

Cindy Winegarden

Hi Ivan and Carsten,

You're right. A FoxPro date is represented in text as {mm/dd/yyyy} (assuming
American date style) and the strict format as Carsten pointed out is
{^yyyy/mm/dd}. A SQL Command might look like:

strSQL = "Insert Into MyTable (DateField) Values ({07/12/2005})"

You can also use the FoxPro Date() function which takes the year, month, and
day in Numeric/Integer format as parameters.

strSQL = "Insert Into MyTable (DateField) Values (Date(2005, 7, 12)}

If you're actually working with dBase files and not FoxPro files YMMV.
 
I

Ivan V via DotNetMonster.com

Dear both you all, that works for me perfectly and can sole my problem
already. Thanks a lot!!!!
 
Top