SALVAR DADOS DE UM DATAGRID NO BD!
Citação:Dim row As DataRow = table.NewRow()
row("codigo") = representante.codigo
row("nome") = representante.nome
row("nmReduz") = representante.nmReduz
row("endereco") = representante.endereco
row("bairro") = representante.bairro
row("uf") = representante.estado
row("cep") = representante.cep
row("cgc") = representante.cgc
row("fax") = representante.fax
row("telefone") = representante.telefone
row("email") = representante.email
row("pagina") = representante.pagina
row("login") = representante.login
row("senha") = representante.senha
table.Rows.Add(row)
Next
Dim strCn As String = "DataSource = \AFV\BdAFV\SoccolBd.sdf"
Dim Cn As System.Data.SqlServerCe.SqlCeConnection = New System.Data.SqlServerCe.SqlCeConnection(strCn)
' Dim DSet As New Data.DataSet(), SQLStr As String
Dim strSQL As String = "INSERT INTO WsRepresentante (Codigo, Nome, NmReduzido, Endereco, Bairro, Uf, Cep, Cpf, Fax, Fone, Email, Login, Senha) VALUES ('representante.codigo', 'representante.nome', 'representante.nmReduz', 'representante.endereco', 'representante.bairro', 'representante.estado', 'representante.cep', 'representante.cgc', 'representante.fax', 'representante.fone', 'representante.email', representante.login', 'representante.senha')"
Dim cmd As New SqlCeCommand(strSQL, Cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Mas não está populando o bd!
Citação:Try
Dim WsAfv As New br.com.siteteste.www.serverwsRepresentantes
Dim server As New br.com.siteteste.www.serverwsRepresentantes
Dim representantes() As br.com.siteteste.www.Representantes = server.listarRepresentantes()
Dim dataset As New DataSet("dataset")
Dim table As New DataTable("table")
table.Columns.Add(New DataColumn("codigo"))
table.Columns.Add(New DataColumn("nome"))
table.Columns.Add(New DataColumn("nmReduz"))
table.Columns.Add(New DataColumn("endereco"))
table.Columns.Add(New DataColumn("bairro"))
table.Columns.Add(New DataColumn("estado"))
table.Columns.Add(New DataColumn("cep"))
table.Columns.Add(New DataColumn("cgc"))
table.Columns.Add(New DataColumn("fax"))
table.Columns.Add(New DataColumn("telefone"))
table.Columns.Add(New DataColumn("email"))
table.Columns.Add(New DataColumn("pagina"))
table.Columns.Add(New DataColumn("login"))
table.Columns.Add(New DataColumn("senha"))
dataset.Tables.Add(table)
For Each representante As br.com.siteteste.www.Representantes In representantes
Dim row As DataRow = table.NewRow()
row("codigo") = representante.codigo
row("nome") = representante.nome
row("nmReduz") = representante.nmReduz
row("endereco") = representante.endereco
row("bairro") = representante.bairro
row("uf") = representante.estado
row("cep") = representante.cep
row("cgc") = representante.cgc
row("fax") = representante.fax
row("telefone") = representante.telefone
row("email") = representante.email
row("pagina") = representante.pagina
row("login") = representante.login
row("senha") = representante.senha
table.Rows.Add(row)
Next
Dim strCn As String = "DataSource = \AFV\BdAFV\SoccolBd.sdf"
Dim Cn As System.Data.SqlServerCe.SqlCeConnection = New System.Data.SqlServerCe.SqlCeConnection(strCn)
' Dim DSet As New Data.DataSet(), SQLStr As String
Dim strSQL As String = "INSERT INTO WsRepresentante (Codigo, Nome, NmReduzido, Endereco, Bairro, Uf, Cep, Cpf, Fax, Fone, Email, Login, Senha) VALUES ('representante.codigo', 'representante.nome', 'representante.nmReduz', 'representante.endereco', 'representante.bairro', 'representante.estado', 'representante.cep', 'representante.cgc', 'representante.fax', 'representante.fone', 'representante.email', representante.login', 'representante.senha')"
Dim cmd As New SqlCeCommand(strSQL, Cn)
Cn.Open()
cmd.ExecuteNonQuery()
Cn.Close()
Catch ex As Exception
End Try
Dim strCn As String = "DataSource = \AFV\BdAFV\SoccolBd.sdf"
Dim Cn As SqlCeConnection = New SqlCeConnection(strCn)
Dim strSQL As String = "INSERT INTO WsRepresentante (Codigo, Nome, NmReduzido, Endereco, Bairro, Uf, Cep, Cpf, Fax, Fone, Email, Login, Senha) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"
Dim cmd As New SqlCeCommand(strSQL, Cn)
cmd.Parameters.Add("@codigo")
cmd.Parameters.Add("@nome")
cmd.Parameters.Add("@nmReduz")
cmd.Parameters.Add("@endereco")
cmd.Parameters.Add("@bairro")
cmd.Parameters.Add("@uf")
cmd.Parameters.Add("@cep")
cmd.Parameters.Add("@cgc")
cmd.Parameters.Add("@fax")
cmd.Parameters.Add("@telefone")
cmd.Parameters.Add("@email")
cmd.Parameters.Add("@login")
cmd.Parameters.Add("@senha")
Cn.Open()
Dim table As DataTable = CType(DataGrid1.DataSource, DataTable)
For Each row As DataRow In table.Rows
cmd.Parameters(0).Value = row("codigo")
cmd.Parameters(1).Value = row("nome")
cmd.Parameters(2).Value = row("nmReduz")
cmd.Parameters(3).Value = row("endereco")
cmd.Parameters(4).Value = row("bairro")
cmd.Parameters(5).Value = row("uf")
cmd.Parameters(6).Value = row("cep")
cmd.Parameters(7).Value = row("cgc")
cmd.Parameters(8).Value = row("fax")
cmd.Parameters(9).Value = row("telefone")
cmd.Parameters(10).Value = row("email")
cmd.Parameters(11).Value = row("login")
cmd.Parameters(12).Value = row("senha")
cmd.ExecuteNonQuery()
Next
Cn.Close()
Dim server As New br.com.soccolbarbieri.www.serverwsRepresentantes
Dim representantes() As br.com.soccolbarbieri.www.Representantes = server.listarRepresentantes()
Dim table As New Data.DataTable("table")
table.Columns.Add(New Data.DataColumn("nome"))
table.Columns.Add(New Data.DataColumn("login"))
table.Columns.Add(New Data.DataColumn("senha"))
For Each representante As br.com.soccolbarbieri.www.Representantes In representantes
Dim row As Data.DataRow = table.NewRow()
row("nome") = representante.nome
row("login") = representante.login
row("senha") = representante.senha
table.Rows.Add(row)
Next
DataGrid1.DataSource = table
If File.Exists("\My Documents\db.sdf") Then
File.Delete("\My Documents\db.sdf")
End If
Dim engine As SqlCeEngine = New SqlCeEngine("DataSource = \My Documents\db.sdf;")
engine.CreateDatabase()
engine.Dispose()
Dim server As New serverwsRepresentantes
Dim representantes() As Representantes = server.listarRepresentantes()
Dim dataset As New DataSet("dataset")
Dim table As New DataTable("table")
table.Columns.Add(New DataColumn("codigo"))
table.Columns.Add(New DataColumn("nome"))
dataset.Tables.Add(table)
For Each representante As Representantes In representantes
Dim row As DataRow = table.NewRow()
row("codigo") = representante.codigo
row("nome") = representante.nome
table.Rows.Add(row)
Next
DataGrid1.DataSource = table
Dim connection As SqlCeConnection = New SqlCeConnection("DataSource = \My Documents\db.sdf;")
Dim command As New SqlCeCommand("CREATE TABLE WsRepresentante (Codigo ntext, Nome ntext)", connection)
connection.Open()
command.ExecuteNonQuery()
command.CommandText = "INSERT INTO WsRepresentante ( Codigo, Nome ) VALUES ( ?, ? )"
command.Parameters.Add("@codigo", DBNull.Value)
command.Parameters.Add("@nome", DBNull.Value)
For Each row As DataRow In table.Rows
command.Parameters(0).Value = row("codigo")
command.Parameters(1).Value = row("nome")
command.Prepare()
command.ExecuteNonQuery()
Next
connection.Close()