Results 1 to 15 of 15

Thread: [RESOLVED] To Database

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [RESOLVED] To Database

    Hi,

    First Steps
    I have a code to generate A
    I have another line of code that will generate another code from A (called B)


    2nd Step
    I want in a table two columns, one for A one for B

    I want the data A and B to be inserted in the database after the First Steps is done.
    Ex. line #1 of the table, B shud be the generated code for A.

    I'm able to do the first step, but i don't know how i shud insert the data to the database?
    Can you please help me.
    my db is SQL2005
    thx

  2. #2

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    can someone please help me

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To Database

    What is it that you actually want? You've given us no information about what A and B are. Is that even relevant? Are you just asking how to save data to a database? If so then that's what you should say rather than all that other irrelevant stuff that only clouds the issue. If you actually do want something other than that then you're going to have to explain it more clearly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    Hi, i just want to know how to save it after both are generated.

    thx

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To Database

    Both what?! We don't even know what they are.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    strings just texts

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To Database

    As far as I can see all this talk of A and B is completely irrelevant and all you want to know is how to save some data to a database. As I said earlier, if that's all you wanted then that's what you should have said because all that other stuff simply confused the issue. I suggest that you read this.

    If I'm wrong and you really do want something more then I have no idea what it is so I can't help further until you provide a full and clear description.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    Hi,

    can you just please show me how to save A and B on my DB.

    Thanks

  9. #9
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: To Database

    What is your DB?

  10. #10

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    MY DATABASE! SQL 2005 as i said in my fist post!

  11. #11
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: To Database

    SQL 2005 as i said in my fist post!
    Of course - how silly of me. Obviously thats all the information needed.

  12. #12

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    ....
    Last edited by met0555; Apr 20th, 2009 at 04:52 AM.

  13. #13

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    well this was the code i was searching for. But i still have a problem when it save it to the database. B do not correspond to A.
    if normaly customer1 >>>> 000002
    now it shows customer1 >>>> 000003

    Dim Connection As New SqlConnection
    Dim mySqlCommand As SqlCommand = New SqlCommand
    Dim a As String
    Connection.ConnectionString = ("Data Source=...")
    Connection.Open()

    mySqlCommand.Connection = Connection
    Try
    mySqlCommand.CommandText = "INSERT INTO ab (a, b) VALUES (@a, @b)"

    Dim InsertCommand As SqlCommand = New SqlCommand

    mySqlCommand.Parameters.AddWithValue("@a", AB2generator(5))
    a = AB2generator(5)
    mySqlCommand.Parameters.AddWithValue("@b", abgenerator(a))





    mySqlCommand.ExecuteNonQuery()
    MessageBox.Show("New Customer Added To Your Database")
    Catch ex As Exception
    MessageBox.Show("Customer could not be added!" & ex.Message)
    Finally
    If Connection.State = ConnectionState.Open Then
    Connection.Close()
    End If
    End Try
    thanks
    Last edited by met0555; Apr 20th, 2009 at 11:57 AM.

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: To Database

    We still have no idea what A and B are and what AB2generator and abgenerator actually do. If it's inserting the values that you're generating then your question is answered. How to generate the right values is something that we don't have enough information to say.

    Having said that, I would have thought that this:
    Code:
    mySqlCommand.Parameters.AddWithValue("@a", AB2generator(5))
    a = AB2generator(5)
    mySqlCommand.Parameters.AddWithValue("@b", AB2generator(a))
    should be this:
    Code:
    a = AB2generator(5)
    mySqlCommand.Parameters.AddWithValue("@a", a)
    mySqlCommand.Parameters.AddWithValue("@b", abgenerator(a))
    I have no idea whether that will fix the problem but there certainly doesn't seem to be a reason to call AB2generator twice.

    Finally, please wrap your code snippets in CODE or VBCode tags. We shouldn't have to ask after over 900 posts.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: To Database

    ok, thanks it works

Posting Permissions

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



Click Here to Expand Forum to Full Width