データを更新するためのストアド プロシージャを呼び出すコマンド フィールド編集ボタンを使用して、グリッドビューで asp.net を使用して Web アプリケーションに取り組んでいますが、更新中に
次のエラーが表示されます。
プロシージャまたは関数 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
返信待ち
あなたの助けは大歓迎です:)