Text Box into a Database NullReferenceException

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TransMayernik751
    New Member
    • Mar 2009
    • 3

    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 NullReferenceEx ception. 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:

    Code:
    protected void btnDelete_Click(object sender, EventArgs e)
        {
            SqlDataSource1.InsertParameters["user_username"].DefaultValue = this.txtUsername.Text;
            SqlDataSource1.InsertParameters["user_password"].DefaultValue = this.txtPassword.Text;
            SqlDataSource1.InsertParameters["user_email"].DefaultValue = this.txtEmail.Text;
            SqlDataSource1.InsertParameters["user_altEmail"].DefaultValue = this.txtAltEmail.Text;
            SqlDataSource1.InsertParameters["user_securityQuestion1"].DefaultValue = this.txtSecurityQuestion1.Text;
            SqlDataSource1.InsertParameters["user_securityQuestion2"].DefaultValue = this.txtSecurityQuestion2.Text;
            SqlDataSource1.InsertParameters["user_securityQuestion3"].DefaultValue = this.txtSecurityQuestion3.Text;
        }
    When I click it, I get a NullReferenceEx ception. Any ideas?

    Thanks!
    Last edited by tlhintoq; Mar 31 '09, 02:29 AM. Reason: [CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.txtAltEmai l.Text and their values will be shown. You should see something that has a value of null

    Comment

    • TransMayernik751
      New Member
      • Mar 2009
      • 3

      #3
      Originally posted by tlhintoq
      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.
      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?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        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?

        Comment

        • TransMayernik751
          New Member
          • Mar 2009
          • 3

          #5
          It says that the insert parameter is NULL. How do I fix this?

          Code:
          		SqlDataSource1.InsertParameters["user_username"]	null	System.Web.UI.WebControls.Parameter

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Research, I guess.
            SQL is not my area.

            Comment

            Working...