如何解决这个问题“过程或函数”spsaveuserdetails'期望参数'@mobile',它未被提供。“ [英] how to solve this" "Procedure or function 'spsaveuserdetails' expects parameter '@mobile', which was not supplied."

查看:67
本文介绍了如何解决这个问题“过程或函数”spsaveuserdetails'期望参数'@mobile',它未被提供。“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

业务对象==================

 使用系统; 
使用 System.Data;
使用 System.Configuration;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Xml.Linq;
命名空间 BussinessObject
{

/// < 摘要 >
/// UserBO
的摘要说明
/// < / summary >
public class UserBO
{
private string _Name;
private string _Address;
private string _Email;
private string _MobileNO;
public string 名称
{
get { return _Name; }
set {_ Name = value ; }
}
public string 地址
{
get { return _Address; }
set {_ Address = value ; }
}
public string 电子邮件
{
get { return _Email; }
set {_Email = value ; }
}
public string MobileNO
{
get { return _MobileNO; }
set {_ MobileNO = value ; }
}



public UserBO()
{
< span class =code-comment> //
// < span class =code-comment> TODO:在此处添加构造函数逻辑
//
}
}
}





========= ===============================

数据访问层

使用System;

使用System.Data;

使用System.Configuration;

使用System.Linq;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI。 HtmlControls;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Xml .Linq;

使用System.Data.SqlClient;

使用B ussinessObject;

命名空间DataAccess

{



///< summary>

/// UserDA的摘要说明

///

公共类UserDA

{

SqlConnection con = new

SqlConnection(ConfigurationManager.ConnectionStrings [DBCS]。ToString());

// public string cs = ConfigurationManager.ConnectionStrings [DBCS]。ConnectionString;

// SqlConnection con = new SqlConnection(cs);

public void AddUserdetails(UserBO obj)

{

try

{

SqlCommand cmd = new SqlCommand( spsaveuserdetails,con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue(@ Name,obj.Name);

cmd.Parameters.AddWithValue(@ Address,obj.Address);

cmd.Parameters.AddWithValue(@ Email,obj.Email);

cmd.Parameters.AddWithValue(@ MobileNo,obj.MobileNO);

con.Open();

cmd.ExecuteNonQuery();



con.Close();

}

catch

{throw; }



}

公共UserDA()

{

//

// TODO:在这里添加构造函数逻辑

//

}

}

} ================================================ =====

逻辑层

 使用 System.Web; 
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用 System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Xml.Linq;
使用 DataAccess; // for a允许DataAccess类
使用 BussinessObject; // for acessing bussiness object class
namespace businessobjects
{
public class UserBL
{

public void SaveUserDetailsBL(UserBO doobj)
{
尝试
{
UserDA daobj = new UserDA();
daobj.AddUserdetails(doobj);
}
catch { throw ;}

}
}

/// < 摘要 >
/// UserBL的摘要说明
/// < / summary >

}







====================================

主页

<%@ Page Language =C#AutoEventWireup =trueCodeFile =Default.aspx.csInherits =_ Default%>



<!DOCTYPE html PUB LIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">



< html xmlns =http://www.w3.org/1999/xhtml>

< head runat =server>

< title> Untitled Page< / title>

< / head>

< body>

< form id =form1runat =server>





< tbody>
用户注册

名称 < asp:TextBox ID = txtnameWidth =150pxrunat =server>

地址 < asp:TextBox ID =txAddressWidth =150pxrunat =server>

EmailID < asp: TextBox ID =txtEmailidWidth =150pxrunat =server>

手机号码 < ; asp:TextBox ID =txtmobileWidth =150pxrunat =server>

< asp:按钮ID =BtnSaverunat =serverWidth =100pxText =SaveOnClick =BtnSave_Click/>





< / form>

< / body>

< / html =========================== ==

代码背后

===============

======= ==========

使用System;

使用System.Collections;

使用System.Configuration;

使用System.Data;

使用System.Linq;

使用System.Web;

使用System.Web.Security ;

使用System.Web.UI;

使用System.Web.UI.HtmlControls;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Xml.Linq;

使用BussinessObject;

使用businessobjects;



pub lic partial class _Default:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{



}

protected void BtnSave_Click(object sender,EventArgs e)

{

UserBO obj = new UserBO();

obj.Name = txtname.Text;

obj.Address = txAddress.Text;

obj。 Email = txtEmailid.Text;

obj.MobileNO = txtmobile.Text;

UserBL blobj = new UserBL();

// Name = txtname;

//地址= txAddress;

// Email = txtEmailid;

// MobileNO = txtmobile;

blobj.SaveUserDetailsBL(obj);

}



}

解决方案

< blockquote>尝试更改@MobileNo:

 SqlCommand cmd =  new  SqlCommand(   spsaveuserdetails,con); 
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue( @ Name,obj.Name);
cmd.Parameters.AddWithValue( @ Address,obj.Address);
cmd.Parameters.AddWithValue( @ Email,obj.Email);
cmd.Parameters.AddWithValue( @ MobileNo,obj.MobileNO);

到@Mobile:

 SqlCommand cmd =  new  SqlCommand(  spsaveuserdetails,con); 
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue( @ Name,obj.Name);
cmd.Parameters.AddWithValue( @ Address,obj.Address);
cmd.Parameters.AddWithValue( @ Email,obj.Email);
cmd.Parameters.AddWithValue( @ Mobile,obj.MobileNO);


business objects==================

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace BussinessObject
{

    /// <summary>
    /// Summary description for UserBO
    /// </summary>
    public class UserBO
    {
        private string _Name;
        private string _Address;
        private string _Email;
        private string _MobileNO;
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        public string Address
        {
            get { return _Address; }
            set { _Address = value; }
        }
        public string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }
        public string MobileNO
        {
            get { return _MobileNO; }
            set { _MobileNO = value; }
        }



        public UserBO()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}



========================================
data access layer
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using BussinessObject;
namespace DataAccess
{

/// <summary>
/// Summary description for UserDA
///
public class UserDA
{
SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ToString());
//public string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
//SqlConnection con = new SqlConnection(cs);
public void AddUserdetails(UserBO obj)
{
try
{
SqlCommand cmd = new SqlCommand("spsaveuserdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@Address", obj.Address);
cmd.Parameters.AddWithValue("@Email", obj.Email);
cmd.Parameters.AddWithValue("@MobileNo", obj.MobileNO);
con.Open();
cmd.ExecuteNonQuery();

con.Close();
}
catch
{ throw; }

}
public UserDA()
{
//
// TODO: Add constructor logic here
//
}
}
}=====================================================
logic layer

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DataAccess; // for acessing DataAccess class
using BussinessObject; // for acessing bussiness object class
namespace businessobjects
{
    public class UserBL
    {

        public void SaveUserDetailsBL(UserBO doobj)
        {
            try
            {
                UserDA daobj = new UserDA();
                 daobj.AddUserdetails(doobj);
            }
            catch{throw;}

        }
    }

    /// <summary>
    /// Summary description for UserBL
    /// </summary>

}




====================================
main page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">



User Registration
Name <asp:TextBox ID="txtname" Width="150px" runat="server">
Address <asp:TextBox ID="txAddress" Width="150px" runat="server">
EmailID <asp:TextBox ID="txtEmailid" Width="150px" runat="server">
Mobile Number <asp:TextBox ID="txtmobile" Width="150px" runat="server">
<asp:Button ID="BtnSave" runat="server" Width="100px" Text="Save" OnClick="BtnSave_Click" />


</form>
</body>
</html=============================
code behind
===============
=================
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BussinessObject;
using businessobjects;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void BtnSave_Click(object sender, EventArgs e)
{
UserBO obj = new UserBO();
obj.Name = txtname.Text;
obj.Address = txAddress.Text;
obj.Email = txtEmailid.Text;
obj.MobileNO = txtmobile.Text;
UserBL blobj = new UserBL();
//Name = txtname;
//Address = txAddress;
//Email = txtEmailid;
//MobileNO = txtmobile;
blobj.SaveUserDetailsBL(obj);
}

}

解决方案

Try changing @MobileNo:

SqlCommand cmd = new SqlCommand("spsaveuserdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@Address", obj.Address);
cmd.Parameters.AddWithValue("@Email", obj.Email);
cmd.Parameters.AddWithValue("@MobileNo", obj.MobileNO);

To "@Mobile":

SqlCommand cmd = new SqlCommand("spsaveuserdetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@Address", obj.Address);
cmd.Parameters.AddWithValue("@Email", obj.Email);
cmd.Parameters.AddWithValue("@Mobile", obj.MobileNO);


这篇关于如何解决这个问题“过程或函数”spsaveuserdetails'期望参数'@mobile',它未被提供。“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆