|
-
May 10th, 2007, 05:04 AM
#1
Thread Starter
New Member
i can't save Records to Access Database
hi
i used Textbox,Combobox and Checkbox in form ...
from that .. input records to database .. but ... i can't save
Dim mycon As New OleDbConnection(connstring)
Dim mycmd As New OleDbCommand("INSERT INTO DailyR_tbl (DateIn,DName,Holiday,ComID,DepID,SecID,StaffName,9-10AM,10-11AM,11-12AM,1-2PM,2-3PM,3-4PM,4-5PM) VALUES ( '" & CDate(txtDate.Text) & "','" & Daycombo.SelectedValue.ToString & "','" & Holidaychbox.CheckState.ToString & "','" & Comcombo.SelectedValue.ToString & "','" & Depcombo.SelectedValue.ToString & "','" & Seccombo.SelectedValue.ToString & "','" & Staffcombo.SelectedValue.ToString & "','" & txtJob1.Text & "','" & txtJob2.Text & "','" & txtJob3.Text & "','" & txtJob4.Text & "','" & txtJob5.Text & "','" & txtJob6.Text & "','" & txtJob7.Text & "')", mycon)
If (mycon.State = ConnectionState.Closed) Then
mycon.Open()
End If
Try
mycmd.ExecuteNonQuery()
mycon.Close()
mycon.Dispose()
MessageBox.Show("save successfully")
Catch ex As Exception
MessageBox.Show("Can't Save")
End Try
-
May 10th, 2007, 05:28 AM
#2
Fanatic Member
Re: i can't save Records to Access Database
what is the error message?
-
May 11th, 2007, 04:32 AM
#3
Thread Starter
New Member
Re: i can't save Records to Access Database
OleDbException was caught ::
syntax error in INSERT INTO statement
-
May 11th, 2007, 05:18 AM
#4
Re: i can't save Records to Access Database
It's very difficult to read all of that. I think if there was ever a case for Parameters it's this. Try this, if nothing else it will help you track down the problem:
2 Code:
Dim mycmd As New OleDb.OleDbCommand _
("INSERT INTO DailyR_tbl (DateIn, DName, Holiday, ComID, DepID, SecID, StaffName, 9-10AM, 10-11AM, 11-12AM, 1-2PM, 2-3PM, 3-4PM, 4-5PM) " & _
"VALUES (@myDate, @dayCombo, @holBox, @comCombo, @DepCombo, @SecCombo, @staffCombo, @Job1, @job2, @job3, @job4, @job5, @job6, @job7)", mycon)
mycmd.Parameters.AddWithValue("@myDate", CDate(txtDate.Text))
mycmd.parameters.addwithvalue("@myCombo", Daycombo.SelectedValue.ToString)
mycmd.parameters.addwithvalue("@holBox", Holidaychbox.CheckState.ToString)
mycmd.parameters.addwithvalue("@comCombo", Comcombo.SelectedValue.ToString)
mycmd.parameters.addwithvalue("@depCombo", Depcombo.SelectedValue.ToString)
mycmd.parameters.addwithvalue("@secCombo", Seccombo.SelectedValue.ToString)
mycmd.parameters.addwithvalue("@staffCombo", Staffcombo.SelectedValue.ToString)
mycmd.parameters.addwithvalue("@job1", txtJob1.Text)
mycmd.Parameters.AddWithValue("@job2", txtJob2.Text)
mycmd.Parameters.AddWithValue("@job3", txtJob3.Text)
mycmd.Parameters.AddWithValue("@job4", txtJob4.Text)
mycmd.Parameters.AddWithValue("@job5", txtJob5.Text)
mycmd.Parameters.AddWithValue("@job6", txtJob6.Text)
mycmd.Parameters.AddWithValue("@job7", txtJob7.Text)
-
May 11th, 2007, 05:25 AM
#5
Fanatic Member
Re: i can't save Records to Access Database
try a bsic insert statement see it it works, then add your other bits in slowly....that way you will see where issue is.
Normally I would built up the sql put it out to text box..open up Access and past in SQL into query run that and see if it works...best way to test this stuff
-
May 11th, 2007, 07:42 AM
#6
Re: i can't save Records to Access Database
It looks like you are tring to post date to a text field and are not using single qoutes around the values.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 11th, 2007, 12:51 PM
#7
Fanatic Member
Re: i can't save Records to Access Database
Try putting a breakpoint before the Insert command. Then step into it and hover over your command. Copy the command (it should have the values in it) and take it to Access. You should be able to run the command and it will tell you where your error is at.
Using Visual Studio 2008
Please mark your thread RESOLVED if you no longer need help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|