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

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If conn11.State = ConnectionState.Closed Then
            conn11.Open()
        End If
        If conn12.State = ConnectionState.Closed Then
            conn12.Open()
        End If
        Dim strins As String
        Dim strdel As String
        Dim txt1 As String
        txt1 = ComboBox1.Text
        If Not txt1 = "" Then
            strins = "IF EXISTS(SELECT name FROM sys.tables WHERE name = '" & txt1 & "') select * from " & txt1
            MsgBox(strins)
            cmd = New SqlCommand(strins, conn12)
            dr.Close()
            dr = cmd.ExecuteReader
            If dr.Read Then
                MsgBox("table exists")
                strdel = "delete from [jay1].dbo. " & txt1.ToString
                MsgBox(strdel)
                cmd = New SqlCommand(strdel, conn12)
                dr.Close()
                dr = cmd.ExecuteReader
                MsgBox("records deleted")
                strins = "insert into [jay1].dbo." & txt1.ToString & " select * from [jay].dbo." & txt1.ToString
                MsgBox(strins)
                cmd = New SqlCommand(strins, conn12)
                dr.Close()
                dr = cmd.ExecuteReader
                MsgBox("records inserted into new database")
            Else
                MsgBox("table doesnot exist")
                strins = "select * into [jay1].dbo. " & txt1.ToString & " from [jay].dbo. " & txt1.ToString
                MsgBox(strins)
                cmd = New SqlCommand(strins, conn12)
                dr.Close()
                dr = cmd.ExecuteReader
                MsgBox("new table created and records inserted")
            End If
        Else
            MsgBox("table not selected")
        End If
    End Sub

can ne1 help,,,reply asap,,,thnks in advance

common members,,,waiting for ur reply..

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.