adding records problem

Joined
Jan 27, 2005
Messages
9
Programming Experience
1-3
hi im making a simple program with this code on the add button. i don't know what's wrong with the code here:
VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] cmdAddRecords_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] cmdAddRecords.Click
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] da [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbDataAdapter(command)

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] ds [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet

[/size][size=2][color=#008000][color=#0000ff]Try[/color]

[/color][/size][size=2]command.Connection = connection

connection.Open()

command.CommandText = "INSERT INTO CustomerTransactions (name,mobileNo,date,time,amount,loadBalance) VALUES ( '" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtMobileNo.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtDate.Text & "', '" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtTime.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtAmount.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtLoadBalance.Text & "')"

da.Fill(ds)

connection.Close()

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] checkRecord [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String

[/color][/size][size=2]checkRecord = "date ASC"

dvCustomers.Sort = checkRecord

[/size][size=2][color=#0000ff]Me[/color][/size][size=2].dgCustomerDetails.DataSource = dvCustomers

 

[/size][size=2][color=#008000][size=2][/size][size=2][color=#0000ff]Catch[/color][/size][size=2] ex [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception

MsgBox(ex.Message)

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Try

[/color][/size][/color][/size][size=2][color=#008000][/color][/size][size=2][/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size]

the problem is. whenever i already fill up the text boxes, the message box says syntax error on INSERT INTO statement. if i omit the try-catch-end try code, it highlights the code
da.Fill(ds)
what seems to be the problem here?? im confused.
 
ac2ually the error message says:
an unhandled exception of type 'System.Data.Oledb.OleDbException'
occurred in system.dala.dll

and that's all. that is if i omit the try-catch code.
 
the words name, date and time are reserved words.... offest them with brackets, or rename your fields.


Tg
 
Back
Top