我試圖用asp製作一個simpe應用程序,我有一個問題。過程或函數'stored_pr'期望參數'@name',這是沒有提供
過程或函數'stored_pr'需要參數'@name',它是 未提供的。
我的存儲過程:
ALTER proc [dbo].[spq]
@name nvarchar(max)
as
insert into tableq (name)
Values
(@name)
GO
我的代碼在ASP:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataSet ds = new DataSet();
SqlConnection con;
//Here we declare the parameter which we have to use in our application
SqlCommand cmd = new SqlCommand();
SqlParameter @name = new SqlParameter();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("server=(local); database=**;uid=DefaultAppPool;pwd=*****");
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = ((TextBox)this.Page.FindControl("Pole")).Text;
cmd = new SqlCommand("spq", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
和
<%@ 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/xhtml1transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Pole" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit Record" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
請任何幫助.. 謝謝
作爲參數的類型是'nvarchar'的,你可能需要SqlDbType.NVarChar'正確設置它的值。 –