我正在使用asp.net在我的gridview im上使用命令字段编辑按钮来调用存储过程来更新数据但是在更新时
我收到以下错误:
过程或函数updateprofile指定了太多参数。
描述:
在执行当前Web请求期间发生了未处理的异常 请查看堆栈跟踪以获取有关错误及其位置的更多信息 起源于代码。例外细节:
System.Data.SqlClient.SqlException:过程或函数updateprofile有太多
指定的参数。
这是我的存储过程:
ALTER procedure [dbo].[updateprofile]
@pid int,
@pfirstname varchar(50),
@plastname varchar(50),
@padress varchar(50),
@pemail varchar(50),
@ptelephone varchar(50),
@pbirthday date
as begin
update profile
set firstname = @pfirstname, @plastname = lastname,
@padress = adress, @pemail = email, @ptelephone = telephone,
birthday = @pbirthday
where id = @pid end
这是我的asp代码:
SelectCommand="selectAllProfile" SelectCommandType="StoredProcedure"
UpdateCommand="updateprofile" UpdateCommandType="StoredProcedure"
DeleteCommand="deleteprofile" DeleteCommandType="StoredProcedure"
<UpdateParameters>
<asp:Parameter Name="pid" Type="Int32" />
<asp:Parameter Name="pfirstname" Type="String" />
<asp:Parameter Name="plastname" Type="String" />
<asp:Parameter Name="padress" Type="String" />
<asp:Parameter Name="pemail" Type="String" />
<asp:Parameter Name="ptelephone" Type="String" />
<asp:Parameter DbType="Date" Name="pbirthday" />
</UpdateParameters>
顺便说一下,我遇到了与删除命令相同的错误
这是我的vb代码:
Imports System.Data.SqlClient
Imports System.Data
Imports Class1e
Public Class Profile_test
Inherits System.Web.UI.Page
Dim rc As Integer
Dim inc As Integer
Dim dt As New DataTable
Dim x As New Class1e
Protected Sub Btn_save_Click(sender As Object, e As System.EventArgs) Handles
Btn_save.Click
If id_txt.Text.Length = 0 Then
x.insertProfile(fname_txt.Text, lname_txt.Text, adresss_txt.Text,
email_txt.Text, birthday_txt.Text, phone_txt.Text)
id_txt.Text = "0"
Else
x.updateProfile(id_txt.Text, fname_txt.Text, lname_txt.Text,
adresss_txt.Text,
email_txt.Text, birthday_txt.Text, phone_txt.Text)
End If
GridView1.DataBind()
End Sub
Protected Sub GridView1_Load(sender As Object, e As System.EventArgs) Handles
GridView1.Load
GridView1.Columns(1).Visible = False
End Sub
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow
id_txt.Text = row.Cells(1).Text
fname_txt.Text = row.Cells(2).Text
lname_txt.Text = row.Cells(3).Text
adresss_txt.Text = row.Cells(4).Text
email_txt.Text = row.Cells(5).Text
phone_txt.Text = row.Cells(6).Text
birthday_txt.Text = row.Cells(7).Text
End Sub
Protected Sub btn_new_Click(sender As Object, e As System.EventArgs) Handles
btn_new.Click
fname_txt.Text = ""
lname_txt.Text = ""
adresss_txt.Text = ""
email_txt.Text = ""
phone_txt.Text = ""
birthday_txt.Text = ""
id_txt.Text = ""
End Sub
这是我的vb类代码:
Public Class Class1e
Dim x As String
Public Sub New()
End Sub
Public connectionString As String = ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString
Public cn As SqlConnection = New SqlConnection(connectionString)
Public Sub updateProfile(ByVal id As Integer, ByVal fname As String, ByVal lname As String, ByVal adress As String, ByVal email As String, ByVal birthday As String, ByVal phone As String)
Try
Dim command As SqlCommand = New SqlCommand("updateprofile", cn)
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@pid", id)
If fname.Length = 0 Then
MsgBox("First name is a required file")
Else
command.Parameters.AddWithValue("@pfirstname", fname)
End If
If lname.Length = 0 Then
MsgBox("Last Name is a required file")
Else
command.Parameters.AddWithValue("@plastname", lname)
End If
command.Parameters.AddWithValue("@padress", adress)
If email.IndexOf(".") = -1 Or email.IndexOf("@") = -1 Then
MsgBox("The email format should be name@domain.com")
Else
command.Parameters.AddWithValue("@pemail", email)
End If
If phone.Length = 0 Then
MsgBox("Tel is a required file")
Else
If phone.Length <> 8 Then
MsgBox("The tel should be 8 digits")
Else
command.Parameters.AddWithValue("@ptelephone", phone)
End If
End If
command.Parameters.AddWithValue("@pbirthday", birthday)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
command.ExecuteNonQuery()
MsgBox("1 Record updated ")
Catch ex As Exception
MsgBox(ex.Message)
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
Public Sub deleteProfile(ByVal id As Integer)
Try
Dim command As SqlCommand = New SqlCommand("deleteprofile", cn)
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@pid", id)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
command.ExecuteNonQuery()
MsgBox("1 Record deleted ")
Catch ex As Exception
MsgBox(ex.Message)
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
Public Sub insertProfile(ByVal fname As String, ByVal lname As String, ByVal adress As String, ByVal email As String, ByVal birthday As String, ByVal phone As String)
Try
Dim command As SqlCommand = New SqlCommand("insertprofile", cn)
command.CommandType = CommandType.StoredProcedure
If fname.Length = 0 Then
MsgBox("First name is a required file")
Else
command.Parameters.AddWithValue("@pfirstname", fname)
End If
If lname.Length = 0 Then
MsgBox("Last Name is a required file")
Else
command.Parameters.AddWithValue("@plastname", lname)
End If
command.Parameters.AddWithValue("@padress", adress)
If email.IndexOf(".") = -1 Or email.IndexOf("@") = -1 Then
MsgBox("The email format should be name@domain.com")
Else
command.Parameters.AddWithValue("@pemail", email)
End If
If phone.Length = 0 Then
MsgBox("Tel is a required file")
Else
If phone.Length <> 8 Then
MsgBox("The tel should be 8 digits")
Else
command.Parameters.AddWithValue("@ptelephone", phone)
End If
End If
command.Parameters.AddWithValue("@pbirthday", birthday)
command.Parameters.AddWithValue("@pprocessed", 0)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
command.ExecuteNonQuery()
MsgBox("1 Record inserted ")
Catch ex As Exception
MsgBox(ex.Message)
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try
End Sub
End Class
等待你的回复
非常感谢您的帮助:)
答案 0 :(得分:0)
而非提供
set firstname = @pfirstname, lastname=@plastname,adress = @padress,
email = @pemail,telephone = @ptelephone,birthday = @pbirthday
where id = @pid
你已经给出了
set firstname = @pfirstname, @plastname = lastname,@padress = adress,
@pemail = email, @ptelephone = telephone,birthday = @pbirthday
where id = @pid