我想在sql server上使用vb.net创建一个表,其中值在datagridview中,但更新不起作用

时间:2016-03-23 10:53:39

标签: sql-server vb.net excel datagridview

我试图从我的sql服务器上创建一个表格,从datagridview 这是我的代码

Form2.ShowDialog()
    Dim grid = DirectCast(Me.TabControl1.SelectedTab.Controls(0), DataGridView)
    Static Dim header As New ArrayList
    Dim sql As String
    Dim values As String = ""
    connection = New SqlConnection("Data Source=ABDELOUAHED;Initial Catalog=table_creances;integrated security=true")
    For Each column As DataGridViewColumn In grid.Columns
        column.HeaderText = column.HeaderText.Replace(" ", "_")
        column.HeaderText = column.HeaderText.Replace("é", "e")
        column.HeaderText = column.HeaderText.Replace("'", "")
        header.Add(column.HeaderText)
    Next
    sql = "CREATE TABLE " & Form2.TextBox1.Text & "(" & header(0) & " int PRIMARY KEY NOT NULL," & header(1) & " int," & header(2) & " int," & header(3) & " real," & header(4) & " real," & header(5) & " date," & header(6) & " date," & header(7) & " real," & header(8) & " int)"
    Try
        Dim Mycommand As SqlCommand = New SqlCommand(sql, connection)
        Mycommand.Connection.Open()
        Mycommand.ExecuteNonQuery()
        Mycommand.Connection.Close()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
Try
        cmdBuilder = New SqlCommandBuilder(adapter)
        changes = ds.GetChanges()
        If changes IsNot Nothing Then
            adapter.Update(changes)
        End If
        MsgBox("Changes Done")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

表已创建,但它不包含任何值,更新部分不起作用 任何帮助将非常感激

0 个答案:

没有答案