|
-
May 12th, 2010, 05:08 AM
#1
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.
-
May 12th, 2010, 06:08 AM
#2
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
-
May 12th, 2010, 06:20 AM
#3
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.
-
May 12th, 2010, 06:28 AM
#4
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)
-
May 12th, 2010, 06:33 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|