Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Under the insert button
VB
sql = "insert into student (name,id)" & _

 "Values("& dgvData.CurrentRow.Cell(0).Value &","& dgvData.CurrentRow.Cell(0). Value &")"

connect()
cmd=new OledbCommand (sql,connect)
cmd.ExecuteNonQuery()




That's the code but when I try to insert it doesn't run it displays primary key cannot contain a null value
Posted
Updated 7-Jan-16 22:58pm
v2
Comments
dan!sh 8-Jan-16 4:59am    
What is the primary key for student table? And what are the values that are being sent to insert command.
Richmond Boateng 8-Jan-16 5:17am    
The primary key is the id and the values is what is in the datagridview

1 solution

As the message states, you are sending null as primary key is not allowed. You will need to put a check that insert command is only allowed when the value in Cell(0) of the current row is not null.

Also, you are sending name as primary key. Is that intentional? If yes then, there could be a problem if there are two people with same name.
 
Share this answer
 
v2

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