我的存储过程无法正常工作,我正在尝试插入新行。 [英] My stored procedure is not working, I'm trying to insert new row.

查看:99
本文介绍了我的存储过程无法正常工作,我正在尝试插入新行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是我的存储过程: -



Hi,

This is my stored procedure:-

ALTER PROCEDURE [dbo].[val]
(
	@Name1 varchar(20),
	@Amount char(10)
)
AS
	BEGIN
		Insert into store (Name1, Amount)
		values (@Name1, @Amount)
	END



在Button_Click上我做了: -




And on Button_Click I did:-

protected void Button1_Click(object sender, EventArgs e)
    {
        string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS; initial catalog=master; integrated security=true";
        SqlConnection con = new SqlConnection(str);
        SqlCommand cmd = new SqlCommand("val",con);
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@Name1", SqlDbType.VarChar,20).Value = TextBox1.Text.Trim();
        cmd.Parameters.Add("@Amount", SqlDbType.Char,10).Value = TextBox2.Text.Trim();
        cmd.Connection = con;

        try
        {
            cmd.ExecuteNonQuery();
            Response.Write("Inserted");
        }

        catch (Exception ex)
        {
            throw ex;
        }

        finally
        {
            con.Close();
            con.Dispose();
        }
    }





但每次它捕获异常(ex)并给出错误: -



程序val没有参数和参数提供





提前致谢。



But everytime it catches the Exception (ex) and gives the Error:-

procedure val has no parameters and arguments were supplied


Thanks in advance.

推荐答案

运行此并尝试 -

Run this and try -
ALTER PROCEDURE [dbo].[val]
@Name1 varchar(20),
@Amount char(10)
AS
BEGIN
Insert into store (Name1, Amount)
values (@Name1, @Amount)
END





这里的区别是括号。



The difference here are the brackets.


亲爱的朋友们,



我明白了!这是目录。而不是主人,它应该是新的。我感到很困惑,因为两者都有程序val。
Dear Friends,

I got it! It was the catalog . Instead of "master" it should be "new". I got confused as there was the procedure val in both of them.


这篇关于我的存储过程无法正常工作,我正在尝试插入新行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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