2013-08-19 2 views
0

Я работаю на веб-приложений с использованием ASP.NET на моем GridView им с помощью кнопки редактирования команда поля, которая вызывает хранимую процедуру для обновления данных, но при обновленииПроцедура или функция deleteprofile имеет слишком много аргументов указано

Я получаю следующее сообщение об ошибке:

Procedure or function updateprofile has too many arguments specified.

Description:
An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it
originated in the code.

Exception Details:
System.Data.SqlClient.SqlException: Procedure or function updateprofile has too many
arguments specified.

Это моя хранимая процедура:

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 

И это мой жерех код:

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 [email protected]") 
     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 [email protected]") 
     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

я добавил ошибку для UpdateCommand – User7291

+0

любая помощь плз :( – User7291

+0

Попробуйте добавить день рождения, как даты вместо строки (vb code) – Heslacher

ответ

0

вместо того чтобы дать

set firstname = @pfirstname, [email protected],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 
+0

Я исправил его как и предложил, и я все равно получаю ту же ошибку – User7291

+0

Сначала вы проверили свой код в sqlserver. – Sasidharan

+0

Моя процедура работает очень хорошо! Я использую ту же процедуру на другой странице, и она работает отлично! – User7291

Смежные вопросы