我试图通过调用存储过程将数据插入到 SQL Server 数据库中,但出现错误
*Procedure or function 'Insertion' expects parameter '@Emp_no', which was not supplied*
我的存储过程称为插入。我已经彻底检查过了,没有遗漏任何参数,我也用标签检查过。标签显示了值,但我不知道为什么会出现错误。
我的代码是
try
{
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Clear();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Insertion";
cmd.Connection = con;
if (rdb_Male.Checked)
{
int @Emp_no = Convert.ToInt32(txtbx_Empno.Text);
string @Emp_name = txtbx_Emp_Name.Text;
double @phone = Convert.ToDouble(txtbx_Phone.Text);
string @Email = txtbx_Email.Text;
string @Password = txtbx_Pwd.Text;
string @Gender = rdb_Male.Text;
DateTime @Dob = Convert.ToDateTime(dob);
string @Address = txtbx_Address.Text;
string @Designation = txtbx_Designation.Text;
string @Qualification = txtbx_Qual.Text;
double @Experience = Convert.ToDouble(txtbx_Exp.Text);
double @Salary = Convert.ToDouble(txtbx_Sal.Text);
DateTime @Doj = Convert.ToDateTime(doj);
}
else if (rdb_Female.Checked)
{
int @Emp_no = Convert.ToInt32(txtbx_Empno.Text);
string @Emp_name = txtbx_Emp_Name.Text;
double @phone = Convert.ToDouble(txtbx_Phone.Text);
string @Email = txtbx_Email.Text;
string @Password = txtbx_Pwd.Text;
string @Gender = rdb_Female.Text;
DateTime @Dob = Convert.ToDateTime(dob);
string @Address = txtbx_Address.Text;
string @Designation = txtbx_Designation.Text;
string @Qualification = txtbx_Qual.Text;
double @Experience = Convert.ToDouble(txtbx_Exp.Text);
double @Salary = Convert.ToDouble(txtbx_Sal.Text);
DateTime @Doj = Convert.ToDateTime(doj);
}
if (con.State==ConnectionState.Closed)
con.Open();
LABEL.Text = txtbx_Empno.Text;
cmd.ExecuteNonQuery();
lbl_Errormsg.Visible = true;
lbl_Errormsg.Text = "Record Inserted Successfully";
con.Close();
}
存储过程是
ALTER PROCEDURE dbo.Insertion
(
@Emp_no int,
@Emp_name varchar(30),
@phone numeric(10,0),
@Email varchar(30),
@Password varchar(10),
@Gender varchar(6),
@Dob date,
@Address varchar(100),
@Designation varchar(20),
@Qualification varchar(20),
@Experience numeric(4,2),
@Salary numeric(10,2),
@Doj date
)
AS
Begin
Insert into Register (Emp_no, Emp_name, phone, Email, Password, Gender, Dob, Address, Designation, Qualification, Experience, Salary, Doj)
Values(@Emp_no, @Emp_name, @phone, @Email, @Password, @Gender, @Dob, @Address, @Designation, @Qualification, @Experience, @Salary, @Doj)
End
请帮帮我。提前致谢。
最佳答案
只是提个醒,它可能会为人们省去很多时间来寻找灵魂。如果您遵循此处的建议,例如使用 AddWithValue 传递参数,并且您已验证所有内容,但仍然收到错误消息“未提供”,请检查您是否已设置命令对象的 CommandType 属性到 CommandType.StoredProcedure。
不设置此属性会产生相同的消息,相信我!希望对某人有所帮助。
关于c# - 存储过程或函数需要未提供的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640094/
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我不确定传递给方法的对象的类型是否正确。我可能会将一个字符串传递给一个只能处理整数的函数。某种运行时保证怎么样?我看不到比以下更好的选择:defsomeFixNumMangler(input)raise"wrongtype:integerrequired"unlessinput.class==FixNumother_stuffend有更好的选择吗? 最佳答案 使用Kernel#Integer在使用之前转换输入的方法。当无法以任何合理的方式将输入转换为整数时,它将引发ArgumentError。defmy_method(number)
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
两者都可以defsetup(options={})options.reverse_merge:size=>25,:velocity=>10end和defsetup(options={}){:size=>25,:velocity=>10}.merge(options)end在方法的参数中分配默认值。问题是:哪个更好?您更愿意使用哪一个?在性能、代码可读性或其他方面有什么不同吗?编辑:我无意中添加了bang(!)...并不是要询问nobang方法与bang方法之间的区别 最佳答案 我倾向于使用reverse_merge方法:option