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