When I try to insert a record into my mysql database, I keep getting the following error.
When I allow that DB to accept null values this code simply adds a blank field into the db.
Does anyone know what I doing wrong?
--------------ERROR------------
ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.7-nt-max]Column 'fname' cannot be null
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Odbc.OdbcException: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.7-nt-max]Column 'fname' cannot be null
Source Error:
Line 20: Line 21: MyConn.Open()Line 22: cmd.ExecuteNonQueryLine 23: Line 24: label1.visible="true"
--------------ERROR------------
HTML Code:
<form id="form1" runat="Server" >
<table border="0">
<tr>
<td align="right">fname</td>
<td> <asp:textbox id="frmfname" runat="server" />
<asp:RequiredFieldValidator
runat="server"
id="vldfname"
ControlToValidate="frmfname"
ErrorMessage="First Name is required"
display="dynamic">
The fname field is Required!
</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:button id="button1" Text="Insert" onclick="doInsert" runat="server" />
<asp:Button id="button2" causesvalidation="false" Text="View Names" onclick="viewthem" runat="server" />
<asp:Button id="button3" Text="Clear" onclick="cleartextboxes" causesvalidation="false" runat="server" />
</td>
</tr>
</table>
Code:
Sub doInsert(Source as Object, E as EventArgs)
Dim strMyConn as string = "DRIVER={MySQL ODBC 3.51 Driver};"
strMyConn += "SERVER=localhost;"
strMyConn += "DATABASE=***;"
strMyConn += "USER=root;"
strMyConn += "PASSWORD=***;"
strMyConn += "OPTION=3;"
Dim MySQL as string = "Insert into dummy (fname) values (@fname)"
Dim MyConn As odbcConnection = New odbcConnection(strMyConn)
Dim Cmd as New odbcCommand(MySQL, MyConn)
cmd.Parameters.Add(New odbcParameter("@fname", frmfname.text))
MyConn.Open()
cmd.ExecuteNonQuery
label1.visible="true"
BindData()
MyConn.Close()
label1.text = "Your data has been received!"
End Sub