Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2007
    Posts
    42

    Unanswered: insert statement

    my insert statement got no error but when i check my table the values were not inserted actually.. what maybe the problem?

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    what's the statement? post it here. also post the table DDL.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by wishlister
    my insert statement got no error but when i check my table the values were not inserted actually.. what maybe the problem?
    I suspect that something didn't work as you expected.

    As jezemine suggested, we could help a lot more if you posted the DDL to create the table and the DML that has you puzzled.

    -PatP

  4. #4
    Join Date
    Feb 2007
    Posts
    42
    my DDL is not hard coded. i have 5 columns in my Cust table(ID, PW, Name, Contact, Add) and the data types are all varchar just having different sizes. the password(PW) is auto generated in my code so i allow nulls for this just for the mean time.

    the second problem i encounter is that it has error about the violation of primary key. how can i check that if i can't see the values i inserted in the table? and besides, I'm sure that I'm not entering duplicate primary keys but the error is still the same.

    additionally, if you can also help... the speed of my application is very slow. that's only my code and it's responding slooowly... i can't imagine how it will run if i already have a lot of codes.

    Code:
    cmd.CommandText = "INSERT INTO Cust(ID, Name, Contact, Add) VALUES('@ID','@Name','@Contact','@Add')";                    cmd.Parameters.Add("@ID",SqlDbType.VarChar).Value=textBoxID.Text;                    cmd.Parameters.Add("@Name",SqlDbType.VarChar).Value=textBoxName.Text;                    cmd.Parameters.Add("@Contact",SqlDbType.VarChar).Value=textBoxContact.Text;                   cmd.Parameters.Add("@Add",SqlDbType.VarChar).Value=textBoxAdd.Text;

  5. #5
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    you want to remove the single quotes around the parameters:

    INSERT INTO Cust(ID, Name, Contact, Add)
    VALUES(@ID,@Name,@Contact,@Add)

    very likely, the reason you are seeing pk violations is because you kept trying to insert the value '@ID' into the pk column.

    You might want to (re)read the examples here:
    http://msdn2.microsoft.com/en-us/lib...arameters.aspx
    Last edited by jezemine; 03-25-07 at 23:07.

  6. #6
    Join Date
    Feb 2007
    Posts
    42
    it has no errors now but still, i can't see in my table the values i inserted. no changes

  7. #7
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Why don't you use stored procedures?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  8. #8
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    when you check to see if the values are there, are you sure you are looking at the same database/table that your app is inserting to?

    what method are you using to verify the values are there? SSMS, QA, or what? what query are you issuing?

  9. #9
    Join Date
    Mar 2004
    Posts
    190
    Quote Originally Posted by Brett Kaiser
    Why don't you use stored procedures?
    Because he/she is not taking the time to read the manual or even check help. When people refer him/her to sites with information, he/she ignores it and continues to ask the same question.

    Looking for quick answers and other people to solve your SQL problems for you is not going to teach you anything. Reading the manual or actually bothering to read what people are sending you is also important.
    "An adventure is only an inconvenience rightly understood; an inconvenience is only an adventure wrongly considered." ~G.K. Chesterton

  10. #10
    Join Date
    Feb 2007
    Posts
    42
    how sure are you that i didn't read and tried those links? you don't know how i take time reading related articles just to answer my question. if you have nothing to say good, then better fall silent. I'm not forcing everyone here to answer my question especially you! besides, there's a lot of forums that can help me... more patient! I can't blame myself for being slow if you think so, because I'm just new. Don't you realize that you just post here in my thread just to say that.. well, thank you for having time insulting me.

  11. #11
    Join Date
    Mar 2004
    Posts
    190
    Your welcome.

    I am sure you'll have better luck with those patient forums.

    Godspeed.
    "An adventure is only an inconvenience rightly understood; an inconvenience is only an adventure wrongly considered." ~G.K. Chesterton

  12. #12
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by wishlister
    my insert statement got no error but when i check my table the values were not inserted actually.. what maybe the problem?

    First off, chill

    Second, do you think this post helps us figure out what the problem is?

    Third, why don't you use stored procedures?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  13. #13
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by wishlister
    my insert statement got no error but when i check my table the values were not inserted actually.. what maybe the problem?
    Quote Originally Posted by wishlister
    the second problem i encounter is that it has error about the violation of primary key.
    Care to clarify?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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