Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    3

    Question Unanswered: Column 'fname' cannot be null

    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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what's wrong is that you are probably not supplying a value for the fname field

    this is probably not a mysql problem, so i'll move your question to the asp forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2004
    Posts
    3
    What about changing

    frmtext.text

    to

    frmtext.Text (capitalized T)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •