参数化查询'(@ FAGRC nchar(3),@ FAGRD nchar(1),@ FAGRN nvarchar(50),@ FAGRU ncha'需要参数@FAGRC,它未提供。 [英] Parameterized Query '(@FAGRC nchar(3),@FAGRD nchar(1),@FAGRN nvarchar(50),@FAGRU ncha' expects parameter @FAGRC, which was not supplied.
本文介绍了参数化查询'(@ FAGRC nchar(3),@ FAGRD nchar(1),@ FAGRN nvarchar(50),@ FAGRU ncha'需要参数@FAGRC,它未提供。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好伙计。
需要你的支持。
我试图从中插入数据datagrid进入sql并在插入记录后获取错误。以下是我正在使用的代码:
hello Guys.
need your support again.
I am trying to insert data from datagrid into sql and gets the error after the records have been inserted. the following is the code i am using:
Dim Insert As New SqlCommand("Insert into FAGR(FAGRC,FAGRD,FAGRN,FAGRU) Values(@FAGRC,@FAGRD,@FAGRN,@FAGRU)", connection)
Insert.Parameters.Add(New SqlParameter("@FAGRC", SqlDbType.NChar, 3))
Insert.Parameters.Add(New SqlParameter("@FAGRD", SqlDbType.NChar, 1))
Insert.Parameters.Add(New SqlParameter("@FAGRN", SqlDbType.NVarChar, 50))
Insert.Parameters.Add(New SqlParameter("@FAGRU", SqlDbType.NChar, 3))
For I As Integer = 0 To DataGridView1.Rows.Count-1
Insert.Parameters(0).Value = DataGridView1.Rows(I).Cells(0).Value
Insert.Parameters(1).Value = DataGridView1.Rows(I).Cells(1).Value
Insert.Parameters(2).Value = DataGridView1.Rows(I).Cells(2).Value
Insert.Parameters(3).Value = DataGridView1.Rows(I).Cells(3).Value
Insert.ExecuteNonQuery()
Next
推荐答案
检查行数据:如果第一列的任何行中有null
值,你会得到这个错误。
(找出的一种方法是在For循环中放置一个try ... catch块,并在异常报告 - 然后您可以使用I
来判断哪一行给出错误。)
Check your row data: if you have anull
value in any row of the first column, you will get this error.
(One way to find out is to put a try...catch block inside the For loop, and put a breakpoint on the exception report - you can then useI
to tell which row gives the error.)
这篇关于参数化查询'(@ FAGRC nchar(3),@ FAGRD nchar(1),@ FAGRN nvarchar(50),@ FAGRU ncha'需要参数@FAGRC,它未提供。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文