I'm making a application with two database and want to insert my second database table with value from first database table they have same column but on different database. so i make a datatable to populate my data from first database table and try to insert it on my second database
so i make a datatable to populate my data from first database table and try to insert it on my second database using data from datatable but always error cause string value
Dim ds As DataSet = New DataSetMasBrgSpring
Dim dt As DataTable
dt = ds.Tables("DataTable1")
If DataGridView1.Rows.Count > 0 Then
dt.Rows.Clear()
For i = 0 To DataGridView1.Rows.Count - 1
dt.Rows.Add(DataGridView1.Rows(i).Cells(0).Value, etc..
Dim sql1 As String
Dim dataAdapter As New Data.SqlClient.SqlDataAdapter
Dim command As New Data.SqlClient.SqlCommand
command = "insert into MasbrgSpring (KODEC, WIRE, DIMENSION, STD, NOMLOT, STAT) VALUES (@kodec, @wire,@dimension,@std,@nomlot,@stat)"
command.Parameters.Add("@kodec", SqlDbType.VarChar)
etc...
For i As Integer = 0 To DataGridView1.Rows.Count - 1
command.Parameters(0).Value = DataGridView1.Rows(i).Cells(0).Value
command.Parameters(1).Value = DataGridView1.Rows(i).Cells(1).Value
etc...
str.Open()
COMMANDSQL(sql1)
str.Close()
Next
End If
End Sub
this is sub commandsql:
Public Sub COMMANDSQL(ByVal S As String)
sqlcom = New SqlCommand(S, str)
sqlcom.CommandType = CommandType.Text
sqlcom.ExecuteNonQuery()
End Sub
This is the error I get :
value of type string cannot be converted to 'system.data.sqlclient.sqlcommand'