I’m using a MySql database and I have created a field in my table named ID which is set to auto-increment and not null. However, I’m receiving an error as:
ERROR: Key cannot be null. Parameter name: key
I have given datakeynames="ID" in my GridView. Is there something wrong in this?
When I put a breakpoint at the point of the query and directly insert data to mysql it is inserted without any problem.
Here is my GridView declaration:
<asp:GridView ID="grdUploadedFiles" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="7" DataKeyNames="ID" ..>
And my SQL statement:
INSERT into tbluploadedfilesdetail (FileType,FileName,FileExt,FilePath,WebUrl) VALUES (...)
it gives this error at myobjcon.open() statement
MySqlConnection objMyCon1 = new MySqlConnection();
objMyCon1.Open();
MySqlCommand cmd1 = new MySqlCommand(getSQL1, objMyCon1);
cmd1.ExecuteNonQuery();
objMyCon1.Close();
dbLoad();
At first you have connect to your DB so you need to create a
ConnectionStringthen your code will work,It means that you are on the air and trying to acdcess a parachute that is not in your back. Does it make sense to you?