#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Update table from sql server with datagridview


    Hello,

    I've the following code to fill a datagridview:

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con = getConnect()


    ' Dim Cn As SqlConnection
    ' Cn = New SqlConnection(Cnst)

    Try

    Dim Cmd6 As SqlCommand = con.CreateCommand

    Cmd.CommandText = "Select ViewTotaal.Expr1 As [Totale Verkoop], ViewTotaal.Datum, Datename (weekday, ViewTotaal.Datum) As Dag From ViewTotaal "


    DaKlant = New SqlDataAdapter(Cmd)
    Dim TaKlant As New DataTable
    DaKlant.Fill(TaKlant)
    DataGridView1.DataSource = TaKlant
    DataGridView1.Columns(2).DefaultCellStyle.Format = "dddd"
    DataGridView1.Sort(DataGridView1.Columns(1), _
    System.ComponentModel.ListSortDirection.Descending)

    Cmd6.CommandText = "select TOP 5 * from ValutaUnderwear order by Dagteller desc "

    sAdapter = New SqlDataAdapter(Cmd6)
    Dim sTable As New DataTable
    sAdapter.Fill(sTable)
    DataGridView6.DataSource = sTable
    DataGridView6.Columns(18).Visible = False

    With a button I want to update the table in sql server:


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim con As New SqlConnection

    Try
    Dim cmdBuilder As SqlCommandBuilder

    cmdBuilder = New SqlCommandBuilder(sAdapter)

    Me.sAdapter.Update(sTable)
    MsgBox("Changes Done")
    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try

    End Sub

    When I run the code I get the message that the value cannot be null.

    Can somebody see what I do wrong?

    John
  2. #2
  3. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Location
    Chennai
    Posts
    6
    Rep Power
    0

    NET development forum discussing all


    Hi, my name david . don't know about .Net,i want to learn .It is very useful information thanks to share it

IMN logo majestic logo threadwatch logo seochat tools logo