CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    192

    Datagrid Problem

    Hi,

    I am trying to insert data to my sql database from a datagrid, and have the following error as highlighted, how can I change the code to be able to insert the data to the table


    Code:
    Private Sub Exportdata()
    
            Dim cmd As New SqlCommand
            Dim conn As SqlConnection = GetDbConnection()
            Dim query As String
    
            Dim irow As Integer
    
            For irow = 0 To DataGrid1.Item - 1 
                Try
                    query = "INSERT INTO dbo.tbltest (Pat_eid, event_date) VALUES (" & _
                                DataGrid1.Item(irow).Cells(0).Value & ", '" & _
                                DataGrid1.Item(irow).Cells(1).Value & ")"
    
    
                    cmd = New SqlCommand(query, conn)
                    cmd.ExecuteNonQuery()
    
                Catch ex As Exception
    
                    MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
    
                End Try
    
            Next irow
    
        End Sub

    Thanks
    Last edited by HanneSThEGreaT; May 12th, 2010 at 06:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured