|
-
Apr 19th, 2009, 03:17 PM
#1
Thread Starter
Frenzied Member
[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
-
Apr 20th, 2009, 02:04 AM
#2
Thread Starter
Frenzied Member
Re: To Database
can someone please help me
-
Apr 20th, 2009, 02:19 AM
#3
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.
-
Apr 20th, 2009, 02:23 AM
#4
Thread Starter
Frenzied Member
Re: To Database
Hi, i just want to know how to save it after both are generated.
thx
-
Apr 20th, 2009, 02:35 AM
#5
Re: To Database
Both what?! We don't even know what they are.
-
Apr 20th, 2009, 02:38 AM
#6
Thread Starter
Frenzied Member
-
Apr 20th, 2009, 02:45 AM
#7
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.
-
Apr 20th, 2009, 03:11 AM
#8
Thread Starter
Frenzied Member
Re: To Database
Hi,
can you just please show me how to save A and B on my DB.
Thanks
-
Apr 20th, 2009, 03:15 AM
#9
-
Apr 20th, 2009, 03:36 AM
#10
Thread Starter
Frenzied Member
Re: To Database
MY DATABASE! SQL 2005 as i said in my fist post!
-
Apr 20th, 2009, 03:49 AM
#11
Re: To Database
SQL 2005 as i said in my fist post!
Of course - how silly of me. Obviously thats all the information needed.
-
Apr 20th, 2009, 03:51 AM
#12
Thread Starter
Frenzied Member
Last edited by met0555; Apr 20th, 2009 at 04:52 AM.
-
Apr 20th, 2009, 04:51 AM
#13
Thread Starter
Frenzied Member
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.
-
Apr 20th, 2009, 05:04 AM
#14
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.
-
Apr 20th, 2009, 05:31 AM
#15
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|