473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Text Box into a Database NullReferenceException

Ok, I'm a noob on this forum, so go easy...
I just got back into programming after a two year hiatus. I'm trying to help a buddy get his site off of the ground....

Anyway, I'm developing in ASP.NET using C# and connecting to a MySQL database using the .NET connector provided by Sun. I'm able to successfully establish a connection to a database hosted online and view the data using a GridView object. I'm also able to delete and change rows no problem. However, when I try to insert data into the database, I run into a snag. I get a NullReferenceException. I'm using textboxes for the data to be inserted and a button click event to initiate it. Below is the code for the button:

Expand|Select|Wrap|Line Numbers
  1. protected void btnDelete_Click(object sender, EventArgs e)
  2.     {
  3.         SqlDataSource1.InsertParameters["user_username"].DefaultValue = this.txtUsername.Text;
  4.         SqlDataSource1.InsertParameters["user_password"].DefaultValue = this.txtPassword.Text;
  5.         SqlDataSource1.InsertParameters["user_email"].DefaultValue = this.txtEmail.Text;
  6.         SqlDataSource1.InsertParameters["user_altEmail"].DefaultValue = this.txtAltEmail.Text;
  7.         SqlDataSource1.InsertParameters["user_securityQuestion1"].DefaultValue = this.txtSecurityQuestion1.Text;
  8.         SqlDataSource1.InsertParameters["user_securityQuestion2"].DefaultValue = this.txtSecurityQuestion2.Text;
  9.         SqlDataSource1.InsertParameters["user_securityQuestion3"].DefaultValue = this.txtSecurityQuestion3.Text;
  10.     }
When I click it, I get a NullReferenceException. Any ideas?

Thanks!
Mar 31 '09 #1
5 1940
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.


Probably no text in one of your texboxes, thus textboxwhatever.text is null.

Try it once with something in every box.

Also, try putting a breakpoint at line 3. You can hover the mouse over objects such as this.txtAltEmail.Text and their values will be shown. You should see something that has a value of null
Mar 31 '09 #2
@tlhintoq
My bad. Will do that in the future.

I've tried filling all of the boxes with characters and still nothing. I have debug enabled in web.config and it stops at the first line. It also says that there is data in the text box. Any more ideas?
Mar 31 '09 #3
tlhintoq
3,525 Expert 2GB
Check the rest of the line and see what *is* null...

SqlDataSource1 - Could this have lost scope and is null by the time this is called?
Mar 31 '09 #4
It says that the insert parameter is NULL. How do I fix this?

Expand|Select|Wrap|Line Numbers
  1.         SqlDataSource1.InsertParameters["user_username"]    null    System.Web.UI.WebControls.Parameter
  2.  
Mar 31 '09 #5
tlhintoq
3,525 Expert 2GB
Research, I guess.
SQL is not my area.
Mar 31 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TT (Tom Tempelaere) | last post by:
Hi, Once in a while my application throws an NullReferenceException at startup, however it appears to be occurring in an unknown module. If I debug it and ask to 'break', then there is no source...
0
by: Matthias Kwiedor | last post by:
Hi! I want to create a WebBrowser Control at runtime. So i ported the "at start creation" of the Control to a new routine. Everything works fine, but i implement the BeforeNavigateFix and a...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
0
by: huobazi | last post by:
I have many dropdownlist controls in my ascx (and use LoadControl in a aspx fiel) file,so i write a method "InitList(DropDownList list,string strsql,string TextField,string ValueField)" but when i...
9
by: Xero | last post by:
could anybody describes a scenario where this error will occur? i have visited the page about the NullReferenceException in msdn library but i still have no idea what it is about. thanks. ...
3
by: Jacob.Bruxer | last post by:
Hi, I want to be able to append text using a For loop to each textbox in an array of textboxes that I've created, called tBoxes(). Basically I want to add a number of spaces to each textbox in...
12
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and...
3
by: Sagar | last post by:
Hi. I am working on a project to migrate a web application from 1.1 to 2.0 Within in the DAL of the application, there is a call to below function that builds a command object for later use. ...
11
by: asmx126453 | last post by:
Hey Guys i need help with this last thing i cant get to work The error i get with it is: NullReferenceException was unhandled by user code Object reference not set to an instance of an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.