本文介绍了无法使用存储过程存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嘿朋友, 我正在尝试将值存储在存储过程的数据库中,但它们都不会进入数据库,也不会存储它们。 这是我的存储过程: - ALTER proc [dbo]。[cards] ( @comname varchar ( 100 ), @commes varchar ( 100 ), @ job varchar ( 50 ), @ name varchar ( 200 ) , @ add1 varchar ( 200 ), @ add2 varchar ( 200 ), @ add3 varchar ( 200 ), @ phone varchar ( 10 ), @ fax varchar ( 100 ), @ email varchar ( 100 )) as begin 插入 到 card1(comname,commes,job,name,add1,add2,add3,phone,fax,email) 值( @ comname , @ commes , @ job , @ name , @ add1 , @ add2 , @ add3 , @ phone , @ fax , @ email ) 结束 这是我的C#: - protected void Button1_Click( object sender,EventArgs e) { string str = @ 数据源= DEEPAKSHARMA-PC\SQLEXPRESS;初始目录=新; integrated security = true; SqlConnection con = new SqlConnection(str); con.Open(); 尝试 { if (IsPostBack!= true ) { SqlCommand cmd = new SqlCommand( cards,con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(Text11.Value。 Trim()); cmd.Parameters.Add(Text12.Value.Trim()); cmd.Parameters.Add(Text13.Value.Trim()); cmd.Parameters .Add(Text14.Value.Trim()); cmd.Parameters.Add(Text15.Value.Trim()); cmd.Parameters.Add(Text16.Value.Trim()); cmd.Parameters.Add(Text17.V alue.Trim()); cmd.Parameters.Add(Text18.Value.Trim()); cmd.Parameters.Add(Text19.Value.Trim()); cmd.Parameters.Add(Text20.Value.Trim()); cmd.ExecuteNonQuery(); } } catch (例外情况) { Console.WriteLine( 出了点问题); } 最后 { con.Close(); con.Dispose(); ScriptManager.RegisterClientScriptBlock( this , this .GetType(), alertMessage, alert('数据已成功插入'), true ); } } 另一个问题是每当我刷新页面时它会显示消息数据成功插入。请帮助!! 解决方案 您好Deepak, 请在管理工作室中调试您的存储过程,如视觉工作室代码调试。 DECLARE @comname AS varchar(100) DECLARE @commes AS varchar(100) DECLARE @job AS varchar(50) DECLARE @name AS varchar(200) DECLARE @ add1 AS varchar(200) DECLARE @ add2 AS varchar(200) DECLARE @ add3 AS varchar(200) DECLARE @phone AS varchar(10) DECLARE @传真AS varchar(100) DECLARE @email AS varchar(100) SET @comname = '' SET @commes ='' SET @ job ='' SET @name ='' SET @ add1 ='' SET @ add2 ='' SET @ add3 ='' SET @phone ='' SET @fax ='' SET @email ='' - ALTER proc [dbo ] [卡]的 - ( - @comname varchar(100), - @commes varchar(100), - @job varchar(50), - @name varchar(200), - @ add1 varchar(200), - @ add2 varchar(200), - @ add3 varchar(200), - @phone varchar(10), - @fax varchar(100), - @email varchar(100) - ) - as 开始 插入card1(comname,commes,job,name,add1,add2,add3,phone,fax,email) 值(@ comname,@ commes,@ job,@ name,@ add1,@ add2,@ add3,@ phone,@ fax,@ email) end 我得到了解决方案: - protected void Button1_Click(对象发送者,EventArgs e) { string str = @data source = DEEPAKSHARMA-PC\SQLEXPRESS;初始目录=新; integrated security = true; SqlConnection con = new SqlConnection(str); try { / /if(Page.IsPostBack!=true) { SqlCommand cmd = new SqlCommand(cards,con); con。 Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(@ comname,Text11.Value.Trim()); cmd.Parameters.Add(@ commes,Text12.Value.Trim()); cmd.Parameters.Add(@ job,Text13.Value.Trim ()); cmd.Parameters.Add(@ name,Text14.Value.Trim()); cmd.Parameters.Add(@ add1 ,Text15.Value.Trim()); cmd.Parameters.Add(@ add2,Text16.Value.Trim()); cmd.Parameters。添加(@ add3,Text17.Value.Trim()); cmd.Parameters.Add(@ phone,Text18.Value .Trim()); cmd.Parameters.Add(@ fax,Text19.Value.Trim()); cmd.Parameters.Add(@ email,Text20.Value.Trim()); cmd.ExecuteNonQuery(); ScriptManager.RegisterClientScriptBlock(this,this.GetType(),alertMessage, 警报('数据插入成功'),真实); } } catch(例外情况ex) { Console.WriteLine(出了问题); } 终于 { con.Close(); con.Dispose(); } } 区别在于我没有在cmd.parameter字段中使用列名。 Hey Friends,I'm trying to store values in database in stored procedure, but neither they are going in the database nor they are getting stored.This is my stored procedure:-ALTER proc [dbo].[cards](@comnamevarchar(100),@commesvarchar(100),@jobvarchar(50),@namevarchar(200),@add1varchar(200),@add2varchar(200),@add3varchar(200),@phonevarchar(10),@faxvarchar(100),@emailvarchar(100))asbegininsert into card1 (comname,commes,job,name,add1,add2,add3,phone,fax,email)values (@comname,@commes,@job,@name,@add1,@add2,@add3,@phone,@fax,@email)endAnd this is my C#:-protected void Button1_Click(object sender, EventArgs e) { string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS; initial catalog=new; integrated security=true"; SqlConnection con = new SqlConnection(str); con.Open(); try { if (IsPostBack != true) { SqlCommand cmd = new SqlCommand("cards", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(Text11.Value.Trim()); cmd.Parameters.Add(Text12.Value.Trim()); cmd.Parameters.Add(Text13.Value.Trim()); cmd.Parameters.Add(Text14.Value.Trim()); cmd.Parameters.Add(Text15.Value.Trim()); cmd.Parameters.Add(Text16.Value.Trim()); cmd.Parameters.Add(Text17.Value.Trim()); cmd.Parameters.Add(Text18.Value.Trim()); cmd.Parameters.Add(Text19.Value.Trim()); cmd.Parameters.Add(Text20.Value.Trim()); cmd.ExecuteNonQuery(); } } catch (Exception ex) { Console.WriteLine("Something went wrong"); } finally { con.Close(); con.Dispose(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Data Inserted Successfully')", true); } }Another problem is whenever I refresh the page it shows the message "Data Inserted Successfully". PLEASE HELP!! 解决方案 Hi Deepak, Please debug your stored procedure in management studio like visual studio code debugging.DECLARE@comname ASvarchar(100)DECLARE@commes ASvarchar(100)DECLARE@jobASvarchar(50)DECLARE@nameASvarchar(200)DECLARE@add1ASvarchar(200)DECLARE@add2ASvarchar(200)DECLARE@add3ASvarchar(200)DECLARE@phoneASvarchar(10)DECLARE@faxASvarchar(100)DECLARE@emailASvarchar(100)SET@comname =''SET@commes=''SET@job=''SET@name=''SET@add1=''SET@add2=''SET@add3=''SET@phone=''SET@fax=''SET@email=''-- ALTER proc [dbo].[cards]--(--@comnamevarchar(100),--@commesvarchar(100),--@jobvarchar(50),--@namevarchar(200),--@add1varchar(200),--@add2varchar(200),--@add3varchar(200),--@phonevarchar(10),--@faxvarchar(100),--@emailvarchar(100)--)--asbegininsert into card1 (comname,commes,job,name,add1,add2,add3,phone,fax,email)values (@comname,@commes,@job,@name,@add1,@add2,@add3,@phone,@fax,@email)endWell I got the solution:- protected void Button1_Click(object sender, EventArgs e) { string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS; initial catalog=new; integrated security=true"; SqlConnection con = new SqlConnection(str); try { //if(Page.IsPostBack!=true) { SqlCommand cmd = new SqlCommand("cards", con); con.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@comname",Text11.Value.Trim()); cmd.Parameters.Add("@commes",Text12.Value.Trim()); cmd.Parameters.Add("@job",Text13.Value.Trim()); cmd.Parameters.Add("@name",Text14.Value.Trim()); cmd.Parameters.Add("@add1",Text15.Value.Trim()); cmd.Parameters.Add("@add2",Text16.Value.Trim()); cmd.Parameters.Add("@add3",Text17.Value.Trim()); cmd.Parameters.Add("@phone",Text18.Value.Trim()); cmd.Parameters.Add("@fax",Text19.Value.Trim()); cmd.Parameters.Add("@email",Text20.Value.Trim()); cmd.ExecuteNonQuery(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Data Inserted Successfully')", true); } } catch (Exception ex) { Console.WriteLine("Something went wrong"); } finally { con.Close(); con.Dispose(); } }The difference is I was not using the column name in the cmd.parameter field. 这篇关于无法使用存储过程存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 05:34