Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
VB
Dim con As New OleDbConnection
        Dim cmd As New OleDbCommand
        Dim sql As String
con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\Thesis\Account.accdb")
 sql = "INSERT into tbl_Record(Name,Date,Toothno,Procedure,Amount_Charged,Amount_Paid,Balance,IDrecord) values (@Name, @Date, @Toothno, @Procedure, @Amount_Charged, @Amount_Paid, @Balance, @IDrecord)"
        con.Open()
        cmd = New OleDbCommand(sql, con)
        cmd.Parameters.AddWithValue("@Name", txtdummyconname.Text)
        cmd.Parameters.AddWithValue("@Date", dtpprocdate.Text)
        cmd.Parameters.AddWithValue("@Toothno", txttoothno.Text)
        cmd.Parameters.AddWithValue("@Procedure", txtprocedure.Text)
        cmd.Parameters.AddWithValue("@Amount_Charged", CInt(txtamountcharged.Text))
        cmd.Parameters.AddWithValue("@Amount_Paid", CInt(txtamountpaid.Text))
        cmd.Parameters.AddWithValue("@Balance", CInt(txtdummybal.Text))
        cmd.Parameters.AddWithValue("@IDrecord", CInt(txtlinkID.Text))
        cmd.ExecuteNonQuery()'Problem here<<<<<<'
        tablerecord()
        con.Close()
        MsgBox("Data has been save.")
<pre>
Posted
Updated 28-Sep-14 17:01pm
v2
Comments
Leena 206 28-Sep-14 23:53pm    
can u put error?
Leena 206 28-Sep-14 23:54pm    
error may occur due to any one of the value or more than one value is getting NULL
Jhon Tuya 30-Sep-14 9:04am    
Index or primary key cannot contain a Null value. i got this error after i use this code sql = "INSERT into tbl_Record ([Name],[Date],[Toothno],[Procedure],[Amount_Charged],[Amount_Paid],[Balance],[IDrecord]) values (@Name, @Date, @Toothno, @Procedure, @Amount_Charged, @Amount_Paid, @Balance, @IDrecord)"
[no name] 29-Sep-14 0:10am    
What error you are getting?

It might be caused by the use of keywords as column names - most likely candidate is Date. Try to "escape" all column names:
sql = "INSERT into tbl_Record ([Name],[Date],[Toothno],[Procedure],[Amount_Charged],[Amount_Paid],[Balance],[IDrecord]) values (@Name, @Date, @Toothno, @Procedure, @Amount_Charged, @Amount_Paid, @Balance, @IDrecord)"

Also, I'd like to suggest a space character between table name and opening bracket - Microsoft databse engines normally cope with the lack of a space here, but others (e.g. Oracle) tend to fail.
 
Share this answer
 
Comments
Raul Iloc 29-Sep-14 2:50am    
You have my 5 vote!
Bernhard Hiller 29-Sep-14 3:00am    
Thanks. But something went wrong: "Rating = 0.00 (No votes)"
Do the hamsters eat votes today?
Raul Iloc 29-Sep-14 6:26am    
The showing of the new votes in the CodeProject page is done after some delay.
Now is showing the result, and you could check also the points gain in your Reputation details.
Jhon Tuya 30-Sep-14 9:06am    
Index or primary key cannot contain a Null value. i got this problem after using this code.. im not to familiar with access what do you think my problem in this code?
Jhon Tuya 30-Sep-14 9:10am    
i see the problem i forgot to change my Primary key ID[datatype TEXT] to autonumber... ty guys
In Your Query


INSERT into tbl_Record(Name,Date,Toothno,Procedure,Amount_Charged,Amount_Paid,Balance,IDrecord) values (@Name, @Date, @Toothno, @Procedure, @Amount_Charged, @Amount_Paid, @Balance, @IDrecord)"


Name and Date are Reserved key words that's why the it gives the error.
 
Share this answer
 
Comments
CHill60 12-Oct-14 7:05am    
I'm guessing you are getting downvoted because Bernhard Hiller said the same thing several days ago "It might be caused by the use of keywords as column names"
set ur id column of table auto increment
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900