Click here to Skip to main content
15,908,776 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Convert Pin
Socheat.Net26-Jun-06 22:50
Socheat.Net26-Jun-06 22:50 
GeneralRe: Convert Pin
Dave Kreskowiak27-Jun-06 1:02
mveDave Kreskowiak27-Jun-06 1:02 
Questiondata migration windows application Pin
divyaswati25-Jun-06 21:09
divyaswati25-Jun-06 21:09 
AnswerRe: data migration windows application Pin
Mekong River25-Jun-06 21:29
Mekong River25-Jun-06 21:29 
GeneralRe: data migration windows application [modified] Pin
divyaswati25-Jun-06 21:53
divyaswati25-Jun-06 21:53 
GeneralRe: data migration windows application [modified] Pin
divyaswati28-Jun-06 0:37
divyaswati28-Jun-06 0:37 
GeneralRe: data migration windows application Pin
Mekong River28-Jun-06 5:18
Mekong River28-Jun-06 5:18 
Questiondata migration Pin
divyaswati25-Jun-06 21:06
divyaswati25-Jun-06 21:06 
please help me in completing this module

i want to transfer the data from one database to another within the same server. But there is a problem of identity column that exist in the table and it will unable the code to transfer the data within the new database
my coding is

Dim ObjSrcConnection As System.Data.SqlClient.SqlConnection
Dim ObjDesConnection As System.Data.SqlClient.SqlConnection
Dim TableListConn As SqlConnection
Dim cmd As SqlCommand
Dim ObjSrcCommand As SqlCommand
Dim ObjDesCommand As SqlCommand
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim dr As SqlDataReader
Dim dt As New DataTable
Dim query As String
Dim TableName As String
Dim TableListConnString As String
Dim strConSrc As String
Dim strConDest As String
Dim string1 As String
Dim TableQuery As String
Dim strCol As String
Dim strType As String
Dim sqlQuery As String
Dim intJ As Integer
Dim intK As Integer

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetTable.Click
Validation()
Table()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMigrate.Click

TableName = ListTable.Text
strConSrc = "server=" & txtSrcServer.Text.Trim & ";user id=" & txtUser.Text.Trim & ";password=" & txtPwd.Text.Trim & ";database=" & txtSrcDb.Text.Trim & ""
strConDest = "server=" & txtDesServer.Text.Trim & ";user id=" & txtDesUser.Text.Trim & ";pwd=" & txtDesPwd.Text.Trim & ";database=" & txtDesDb.Text.Trim & ""
ObjSrcConnection = New SqlConnection(strConSrc)
ObjSrcConnection.Open()
ObjDesConnection = New SqlConnection(strConDest)
'con2.ConnectionString = strConDest
ObjDesConnection.Open()
TableQuery = "select * from " & TableName
ObjSrcCommand = New SqlCommand(TableQuery, ObjSrcConnection)
dr = ObjSrcCommand.ExecuteReader(CommandBehavior.CloseConnection)
dt = dr.GetSchemaTable
Dim i As Integer = dt.Rows.Count
For intJ = 0 To i - 1
If intJ = 0 Then
strCol = dt.Rows(intJ).Item(0).ToString()
Else
strCol = strCol & "," & dt.Rows(intJ).Item(0).ToString()
End If
Next
If find1() = True Then
Exit Sub
End If


While dr.Read()
Try
'sqlQuery = "Insert into " & strValue & "(" & strCol & ") Values( " & Convert.ToString(dr.Item()) & "')"
sqlQuery = "Insert into " & TableName & "(" & strCol & ") Values( "
For intK = 0 To i - 1
If (intK = (i - 1)) Then

sqlQuery = sqlQuery & "'" & CStr(dr.Item(intK)) & "'"
Else
sqlQuery = sqlQuery & "'" & CStr(dr.Item(intK)) & "',"
End If
Next
sqlQuery = sqlQuery & ")"
ObjDesCommand = New SqlCommand(sqlQuery, ObjDesConnection)
ObjDesCommand.CommandType = CommandType.Text
Catch ex As Exception
MsgBox("Error in reading :" & ex.Message, MsgBoxStyle.DefaultButton1.Information, "Data Migration")
End Try
Try
ObjDesCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error " & ex.Message, MsgBoxStyle.DefaultButton1.Information, "Data Migration")
Exit Sub
End Try
End While
ObjSrcConnection.Close()
ObjDesConnection.Close()


End Sub
Public Function Table()
Try
TableListConnString = "Server=" & txtSrcServer.Text.Trim & ";uid=" & txtUser.Text.Trim & ";pwd=" & txtPwd.Text.Trim & ";database=" & txtSrcDb.Text.Trim & ""
TableListConn = New SqlConnection(TableListConnString)
query = "select * from sysobjects where type='U'"
cmd = New SqlCommand(query, TableListConn)
TableListConn.Open()
Catch ex As Exception
MsgBox(" Entries are not correct :" & ex.Message, MsgBoxStyle.OKCancel.Information, "Data Migration")
Exit Function
End Try
da = New SqlDataAdapter(cmd)

da.Fill(ds)
ListTable.DataSource = ds.Tables(0).DefaultView
ListTable.DisplayMember = "name"
TableListConn.Close()
TableName = ListTable.Text

End Function
Public Function find1() As Boolean
Dim find2 As String
find2 = "Select name from syscolumns where id = object_id(" & TableName & ")and autoval is not NULL"
If Not (find2 Is Nothing) Then
MsgBox("There is an identity column in the table so we are not able to enter the data in table ", MsgBoxStyle.DefaultButton1.Information, "Data Migration")

Return True
End If
Exit Function
End Function
End Class


divya
AnswerRe: data migration Pin
Coolesh26-Jun-06 1:59
Coolesh26-Jun-06 1:59 
Questioncharacter limit in textbox Pin
mamathy25-Jun-06 20:07
mamathy25-Jun-06 20:07 
AnswerRe: character limit in textbox Pin
rajmani25-Jun-06 20:49
rajmani25-Jun-06 20:49 
AnswerRe: character limit in textbox Pin
Socheat.Net26-Jun-06 0:02
Socheat.Net26-Jun-06 0:02 
AnswerRe: character limit in textbox Pin
Socheat.Net26-Jun-06 0:02
Socheat.Net26-Jun-06 0:02 
Questionimport video files from Digital camera Pin
NyBawa25-Jun-06 19:58
NyBawa25-Jun-06 19:58 
QuestionVisual Studio cannot start debugging...... Pin
angelagke25-Jun-06 16:11
angelagke25-Jun-06 16:11 
AnswerRe: Visual Studio cannot start debugging...... Pin
Mekong River25-Jun-06 21:33
Mekong River25-Jun-06 21:33 
GeneralRe: Visual Studio cannot start debugging...... Pin
angelagke27-Jun-06 0:01
angelagke27-Jun-06 0:01 
GeneralRe: Visual Studio cannot start debugging...... Pin
Mekong River27-Jun-06 0:08
Mekong River27-Jun-06 0:08 
GeneralRe: Visual Studio cannot start debugging...... Pin
angelagke27-Jun-06 15:32
angelagke27-Jun-06 15:32 
QuestionPrinting Labels Pin
micromause25-Jun-06 15:54
micromause25-Jun-06 15:54 
QuestionInserting new records in ADO.NET Pin
TheFoZ25-Jun-06 3:25
TheFoZ25-Jun-06 3:25 
AnswerRe: Inserting new records in ADO.NET Pin
Tamimi - Code25-Jun-06 3:39
Tamimi - Code25-Jun-06 3:39 
GeneralRe: Inserting new records in ADO.NET Pin
TheFoZ25-Jun-06 4:11
TheFoZ25-Jun-06 4:11 
AnswerRe: Inserting new records in ADO.NET Pin
Dave Kreskowiak25-Jun-06 12:47
mveDave Kreskowiak25-Jun-06 12:47 
GeneralRe: Inserting new records in ADO.NET Pin
TheFoZ27-Jun-06 8:09
TheFoZ27-Jun-06 8:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.