Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - INSERT data to database
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

INSERT data to database

 Post Reply Post Reply Page  12>
Author
mike7510uk View Drop Down
Newbie
Newbie


Joined: 05 October 2006
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote mike7510uk Quote  Post ReplyReply Direct Link To This Post Topic: INSERT data to database
    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" />

<

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
mike7510uk View Drop Down
Newbie
Newbie


Joined: 05 October 2006
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote mike7510uk Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2006 at 4:03pm
ah thanks mike, it works perfectly Clap
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2006 at 7:09pm
I am glad to have helped
Back to Top
mike7510uk View Drop Down
Newbie
Newbie


Joined: 05 October 2006
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote mike7510uk Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 09 October 2006 at 2:10pm
make sure that you set
Dim foo as string
foo=textbox1.text
AND NOT
foo=textbox1

Back to Top
mike7510uk View Drop Down
Newbie
Newbie


Joined: 05 October 2006
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote mike7510uk Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.