我需要在SQL中插入一DataGridView
列和两列。DataTable
下面的代码DataGridView
按我想要的顺序逐行插入列,但是该DataTable
列仅插入第一行并将其复制到所有行上。关于如何解决这个问题的任何想法?
_Command = New SqlCommand("insert_student", _Connection)
_Command.CommandType = CommandType.StoredProcedure
_Connection.Open()
_Command.Parameters.Add(New SqlParameter("@_name", SqlDbType.NVarChar))
_Command.Parameters.Add(New SqlParameter("@_m_barrImg", SqlDbType.VarBinary))
_Command.Parameters.Add(New SqlParameter("@_CurrentImageName", SqlDbType.NChar))
_Command.Parameters.Add(New SqlParameter("@_CurrentImageName1", SqlDbType.NChar))
For x = 0 To DataGridView1.RowCount - 1
_Command.Parameters("@_name").Value = DataGridView1.Rows(x).Cells("name4").Value
_Command.Parameters("@_m_barrImg").Value = DataGridView1.Rows(x).Cells("CompanyStatusImage").Value
Dim dt As New DataTable()
For i As Integer = 0 To dt.DefaultView.Count - 1
_Command.Parameters("@_CurrentImageName").Value = dt.Rows(i)("CurrentImageName").ToString
_Command.Parameters("@_CurrentImageName1").Value = dt.Rows(i)("CurrentImageName1").ToString
Next
_Command.ExecuteNonQuery()
Next
存储过程
USE [master]
GO
/****** Object: StoredProcedure [dbo].[insert_student] Script Date: 07/04/2013 21:47:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insert_student] (@_m_barrImg varbinary(max),
@_name nvarchar(max)
as
insert into tblimgdata(name4,CompanyStatusImage)
values (@_name,@_m_barrImg)