CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  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.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Datagrid Problem

    What error do you get??

    Also, please, please use [CODE] tags when posting code.

    It is explained here :

    http://www.codeguru.com/forum/showthread.php?t=403073

  3. #3
    Join Date
    Feb 2009
    Posts
    192

    Re: Datagrid Problem

    The error message are;

    1) Overload resolution failed because no accessible 'item' accepts this number of arguments
    2) Value of type 'integer' cannot be converted to 'System.Windows.Forms.DataGridCell'


    Thank you and next time I'll make sure I enclose the code.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Datagrid Problem

    Ah, it seems as if you have forgotten to specify the column as well, like this :

    Code:
    DataGrid1.Item(irow, COLUMN HERE)

  5. #5
    Join Date
    Feb 2009
    Posts
    192

    Re: Datagrid Problem

    I still have an error here;

    Code:
    For irow = 0 To DataGrid1.Item - 1

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