update the whole table

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

update the whole table

 
0
  #1
Jul 18th, 2008
hii all, i have a query,,it might be simple bt i hav no idea how to do it,,i am creating an application in VB lang using asp.net 2005 and sql server 2005. in my form i have a combo box which displays all the table names from my database say dat1..i have created another database say dat2 with same table n their datatypes..,what i want is when i select a table name and click on update button then the table in dat2 database should be updated with the records from table in dat1.. well i have achieved this but i cant say it as updating..
heres is may code on update button
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. If conn11.State = ConnectionState.Closed Then
  3. conn11.Open()
  4. End If
  5. If conn12.State = ConnectionState.Closed Then
  6. conn12.Open()
  7. End If
  8. Dim strins As String
  9. Dim strdel As String
  10. Dim txt1 As String
  11. txt1 = ComboBox1.Text
  12. If Not txt1 = "" Then
  13. strins = "IF EXISTS(SELECT name FROM sys.tables WHERE name = '" & txt1 & "') select * from " & txt1
  14. MsgBox(strins)
  15. cmd = New SqlCommand(strins, conn12)
  16. dr.Close()
  17. dr = cmd.ExecuteReader
  18. If dr.Read Then
  19. MsgBox("table exists")
  20. strdel = "delete from [jay1].dbo. " & txt1.ToString
  21. MsgBox(strdel)
  22. cmd = New SqlCommand(strdel, conn12)
  23. dr.Close()
  24. dr = cmd.ExecuteReader
  25. MsgBox("records deleted")
  26. strins = "insert into [jay1].dbo." & txt1.ToString & " select * from [jay].dbo." & txt1.ToString
  27. MsgBox(strins)
  28. cmd = New SqlCommand(strins, conn12)
  29. dr.Close()
  30. dr = cmd.ExecuteReader
  31. MsgBox("records inserted into new database")
  32. Else
  33. MsgBox("table doesnot exist")
  34. strins = "select * into [jay1].dbo. " & txt1.ToString & " from [jay].dbo. " & txt1.ToString
  35. MsgBox(strins)
  36. cmd = New SqlCommand(strins, conn12)
  37. dr.Close()
  38. dr = cmd.ExecuteReader
  39. MsgBox("new table created and records inserted")
  40. End If
  41. Else
  42. MsgBox("table not selected")
  43. End If
  44. End Sub
can ne1 help,,,reply asap,,,thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: update the whole table

 
0
  #2
Jul 19th, 2008
common members,,,waiting for ur reply..
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: update the whole table

 
0
  #3
Jul 19th, 2008
Specify u r query clearly,If u have doubt in sql queries,u can go to database forum.whats u r application,u want to send the whole table to next database or further more
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 85
Reputation: johnny.g is an unknown quantity at this point 
Solved Threads: 3
johnny.g johnny.g is offline Offline
Junior Poster in Training

Re: update the whole table

 
0
  #4
Jul 19th, 2008
Originally Posted by greeny_1984 View Post
Specify u r query clearly,If u have doubt in sql queries,u can go to database forum.whats u r application,u want to send the whole table to next database or further more
ooohh dear,,k i wil explain it again wht i want,,in my application i have two database,,but the tables in both the database r exactly same,all the updation occurs in the tables of 1st database.currently in my form i am creating a new table if it doesnot exists in database2 and fill it with the data from the table in database1,,if the table exists then i delete all the records in the table from database 2 and the insert all the details from the table in database 1...what i want is instead of deleting the data and then inserting it from the table i would like to update the table in database 2 from the table in database 1....hop u got ma prob,,,let me kno whethr u got it or not,,,waiting for ur reply,,thnks in advance
Johnny.G
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: update the whole table

 
0
  #5
Jul 19th, 2008
u have same id for the rows u want to update in the two databases,then when ever the row is updated write a query for the database2 at the same time.
May be u can get a better answer in databases forum.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 176
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 13
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: update the whole table

 
0
  #6
Jul 21st, 2008
Sorry Johnny.g
Just wonder, Why do you want to change your code ?
I think your code is already correct.
If I were you I will use that code.
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC