If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Column 'fname' cannot be null

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-04, 09:26
mary2004 mary2004 is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Question 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
Reply With Quote
  #2 (permalink)  
Old 12-13-04, 09:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-13-04, 13:25
Munti Munti is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
What about changing

frmtext.text

to

frmtext.Text (capitalized T)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On