没有给出一个或多个必需参数的值

没有给出一个或多个必需参数的值

本文介绍了没有给出一个或多个必需参数的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在asp.net中使用gridview更新记录时,我收到错误没有给出一个或多个必需参数的值。我正在使用Access数据库。下面是代码(假设使用了OledbConnection和Command)



--------------------- ---------------

When trying to update records using gridview in asp.net I am getting an error "No value given for one or more required parameter". I am using Access Database. below is the code (Assume that OledbConnection and Command are used)

------------------------------------

Protected Sub GridView1_RowUpdating(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)Handles GridView1.RowUpdating

    Dim title as TextBox=CType(GridView1.Rows(e.RowIndex).Cells(1).Controls(0),TextBox)
    Dim des as TextBox=CType(GridView1.Rows(e.RowIndex).Cells(2).Controls(0),TextBox)
     Dim rid as Integer=CInt(GridView1.Rows(e.RowIndex).Cells(0).Text)
     cmd=new OledbCommand("update Aeminitise set AeminitiseTitle=@Title,AeminitiseDesc=@Des where AeminitiseID=rid",conn)
cmd.Parameters.AddWithValue("@Title",title.Text)
cmd.Parameters.AddWithValue("@Des",des.Text)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Response.Write("Data Updates")

推荐答案

cmd=new OledbCommand("update Aeminitise set AeminitiseTitle=@Title,AeminitiseDesc=@Des where AeminitiseID=@rid",conn)
cmd.Parameters.AddWithValue("@Title",title.Text)
cmd.Parameters.AddWithValue("@Des",des.Text)
cmd.Parameters.AddWithValue("@rid",rid)


这篇关于没有给出一个或多个必需参数的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 14:51