Print Page | Close Window

INSERT data to database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=21492
Printed Date: 29 March 2026 at 12:41pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: INSERT data to database
Posted By: mike7510uk
Subject: INSERT data to database
Date Posted: 05 October 2006 at 11:18am
Hi
I am new to asp.net and have created a simple form that the user fills in and presses submit, this action is supposed to send the data they entered to my database, but its not working. I keep getting an error message saying

..."ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.14-nt]Column 'firstname' cannot be null

Below is my .aspx code...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<table style="width: 426px">

<tr>

<td>

Category Name:</td>

<td>

<asp:TextBox ID="firstname" runat="server"></asp:TextBox></td>

<td>

</td>

</tr>

<tr>

<td>

Description:&nbsp;</td>

<td>

<asp:TextBox ID="surname" runat="server"></asp:TextBox></td>

<td>

&nbsp;<asp:Button ID="Button2" runat="server" Text="Add" /></td>

</tr>

</table>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:registerConnectionString %>"

ProviderName="<%$ ConnectionStrings:registerConnectionString.ProviderName %>"

SelectCommand="select firstname,surname from register"

InsertCommand="INSERT INTO register (firstname, surname) VALUES (@firstname, @surname)" >

<InsertParameters>

<asp:Parameter Name="firstname" Type="String" />

<




Replies:
Posted By: michael
Date Posted: 05 October 2006 at 2:25pm
Your code is fine. Maybe its mySQL acting up but for SQL Server this would work just fine.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: mike7510uk
Date Posted: 05 October 2006 at 4:03pm
ah thanks mike, it works perfectly Clap


Posted By: michael
Date Posted: 05 October 2006 at 7:09pm
I am glad to have helped

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: mike7510uk
Date Posted: 09 October 2006 at 10:40am
aaarrrggghhhh i thought it was all sorted out but now i get an error message saying
 
"Error 1 Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'. C:\Documents and Settings\michael\Desktop\smallbusiness_vb1\register.aspx 1"
 
any ideas?


Posted By: michael
Date Posted: 09 October 2006 at 2:10pm
make sure that you set
Dim foo as string
foo=textbox1.text
AND NOT
foo=textbox1



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: mike7510uk
Date Posted: 09 October 2006 at 2:38pm
tried that, same outcome..i read elsewhere that if you remove the "title" from the top of the page it works ok, i tried this and it did work but surely there is another way as now i have no title


Posted By: michael
Date Posted: 09 October 2006 at 6:08pm
The error you specified indicates that you are setting the textbox to a sting, you need to set the VALUE (.text) to a string. That has nothing to do with a title.

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: mike7510uk
Date Posted: 10 October 2006 at 2:58pm
yes, i know but when i remove the title from inside the <%blah blah%> it works!!!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net