Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    sql 2005 express error (2005)

    Hi am trying to insert information into a sql server 2005 express talbe (via a web form). The values section should be taking the information from a textbox control on the webpage. This is the the code:
    -------------------------------------------------------------------------------------------------------------
    Protected Sub EmailAddress_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EmailAddress.Click
    If Me.CheckBox1 IsNot Nothing Then

    SqlDataSource1.InsertCommand = "Insert into tbltest(EmailAddress)values(@EmailAddress)"
    SqlDataSource1.Insert()
    --------------------------------------------------------------------------------------------------------------------------------
    I get the following error
    Cannot insert the value NULL into column 'EmailAddress', table 'COCUMENTS AND SETTINGSACLENDENNINMY DOCUMENTSVISUAL STUDIO 2005WEBSITESORDERTEMPLATEAPP_DATAASPNETDB.MDF.dbo. tblTest'; column does not allow nulls. INSERT fails.
    The statement has been terminated

    _____________________________________
    I've tried:
    "Insert into tbltest(EmailAddress)values('EmailAddress')" which inserts data but it inserts emailaddress and not the address in the textbox.

    I've tried
    "Insert into tbltest(EmailAddress)values([EmailAddress])" but I get a different error about columns.

    Thanks,
    Leesha

  2. #2
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sql 2005 express error (2005)

    Hi Leesha,
    Are setting the textbox value equal to @EmailAddress? The @ symbol is used to indicate a parameter which will be used as a variable within SQLServer; a stored procedure, for example. Since you are executing a sql statement I would expect your insert statement should look something on the order of: VALUES (" & strEmailAddress & ")" where strEmailAddress = the textbox value.
    Hope I understood your concern.
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: sql 2005 express error (2005)

    Hi!
    As I'm sure you can tell, I'm painfully new to sql server and am surrounded by books trying to plod through this stuff. I only tried the @ because I saw it in sample code and thought hmmmm, maybe it would work.

    If you could bear with me and explain what your code is doing.
    VALUES (" & strEmailAddress & ")" where strEmailAddress = the textbox value

    I don't understand the code. Also, I'm asuming that where you have = the texbox value, I'm supposed to put in the name of the textbox???
    When I tried inserting the code the way it is here, to see if I could work through any errors, the first one I get is that strEmailAddress is not declared. The second is that end of statement is expected.

    Thanks,
    Leesha

  4. #4
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sql 2005 express error (2005)

    <P ID="edit" class=small>(Edited by gdrezek on 05-Mar-08 16:04. added single quotes to sql string)</P>Sorry......more complete:

    <><><><><><>
    Dim strEmailAddress as String

    strEmailaddress = YourTextBoxName

    SqlDataSource1.InsertCommand = "Insert into tbltest(EmailAddress)values('" & strEmailAddress & "')"
    SqlDataSource1.Insert()
    <><><><><><><>

    btw.....there are methods using parameters and the @ symbol but they are a bit more involved
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  5. #5
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: sql 2005 express error (2005)

    Hi,

    Thanks for the clarification. I tried the code and changed "yourTextBoxName" to EmailAddress since that is the name of the control. I'm using this on a asp.net 2.0 form on a website. Now I get the error
    BC30311: Value of type 'System.Web.UI.WebControls.textbox' cannot be converted to 'String'.
    I'm not sure what that is referring to but this piece may be beyond the scope of the is lounge and better tackled on the WOPR web forum.
    At lease we're making progress!!!

    Thanks!
    Leesah

  6. #6
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sql 2005 express error (2005)

    Hi Leesha,
    I think you are right in that this question should now be handled by the web forum. My experience in ASP is what's known now as ASP classic. I'm just now getting my ankles wet (just beyond getting one's feet wet <img src=/S/smile.gif border=0 alt=smile width=15 height=15> ) with the .NET stuff and then only for my benefit, not the company I for which I work, so the methods and such don't exactly roll off my fingertips.
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sql 2005 express error (2005)

    What's the address of the WOPR web forum?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: sql 2005 express error (2005)

    If you look at our Main Index, you'll see Web Design, Coding and Scripting in the "Other Serious Stuff" section.

  9. #9
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: sql 2005 express error (2005)

    Hi,
    It's still in test phase so this section isn't posted yet.
    Leesha

  10. #10
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: sql 2005 express error (2005)

    Thanks Hans! The posts here helped me get 3/4 of the way. Now on the web side!

    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •