C#和SQL-Server存储过程 [英] C# and SQL-Server Stored Procedures

查看:74
本文介绍了C#和SQL-Server存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我对存储过程和C#有一点问题。


我有一个存储过程,应该只在桌子上插入一些东西。

例如:


ALTER PROCEDURE DBO.PROC1

AS

插入dbo.Test值(''test'')


当我在Visual Studio Envirment中执行此程序时右键单击

就可以了。它做了它应该的程序过程在我的表中插入一行。

但如果我从C#执行它,它就不会。


SqlCommand cmd = new SqlCommand(" proc1",conn);

cmd.ExecuteNonQuery();


我收到1行已被记录的消息 - 但是表格中没有条目。


有没有人有一些想法我做错了什么?


谢谢!


Jacek

Hello,

I have got a little problem with stored procedures and C#.

I have got a stored procedure which should only insert something in a table.
For example:

ALTER PROCEDURE DBO.PROC1
AS
insert into dbo.Test values (''test'')

when I execute this procedure in my Visual Studio Envirment with right click
on it. It makes what it should The procedure inserts a row in my table.
But if I trie to execute it from C#, it doesn''t.

SqlCommand cmd = new SqlCommand("proc1",conn);
cmd.ExecuteNonQuery();

I get the message that 1 row has been affekted - but there is no entry in
the table.

Does anyone has some ideas what I have done wrong?

Thanks!

Jacek

推荐答案

嗨Jacek,


运行Sql Profiler并查看是否正在调用该过程。 Sql Profile

可以从企业管理器(Sql Server 2000)或Sql Server

Management Studio(Sql Server 2005)启动,两者都来自IIRC的工具菜单。 />

-

Dave Sexton


" J. S. EDV < JS *** @ discuss.microsoft.com写信息

news:86 ************************* ********* @ microsof t.com ...
Hi Jacek,

Run Sql Profiler and see if the procedure is being called at all. Sql Profile
can be launched from Enterprise Manager (Sql Server 2000) or Sql Server
Management Studio (Sql Server 2005), both from the Tools menu, IIRC.

--
Dave Sexton

"J. S. EDV" <JS***@discussions.microsoft.comwrote in message
news:86**********************************@microsof t.com...

您好,


我有存储过程和C#有点问题。


我有一个存储过程,只能在表中插入一些东西。

例如:


ALTER PROCEDURE DBO.PROC1

AS

插入dbo.Test值(''test'')

时,
。它做了它应该的程序过程在我的表中插入一行。

但如果我从C#执行它,它就不会。


SqlCommand cmd = new SqlCommand(" proc1",conn);

cmd.ExecuteNonQuery();


我收到1行已被记录的消息 - 但是表格中没有条目。


有没有人有一些想法我做错了什么?


谢谢!


Jacek
Hello,

I have got a little problem with stored procedures and C#.

I have got a stored procedure which should only insert something in a table.
For example:

ALTER PROCEDURE DBO.PROC1
AS
insert into dbo.Test values (''test'')

when I execute this procedure in my Visual Studio Envirment with right click
on it. It makes what it should The procedure inserts a row in my table.
But if I trie to execute it from C#, it doesn''t.

SqlCommand cmd = new SqlCommand("proc1",conn);
cmd.ExecuteNonQuery();

I get the message that 1 row has been affekted - but there is no entry in
the table.

Does anyone has some ideas what I have done wrong?

Thanks!

Jacek



嗨Dave,


感谢非常快速的答案。我忘了说,我使用的是

Express Edition - 我认为没有Profiler。但是当我用一些更多的插入和更新命令调用更大的

过程时,我得到的消息是XX

行已经受到影响。所以我认为程序已经执行了,因为

已经受到影响的行数类似于更新的数量

和我在peocedure中使用的insert-commands但是没有任何反应。


作为输出参数,我定义了@@ identity,我得到的数字也是

下一个正常用于新行。


" Dave Sexton"写道:
Hi Dave,

thanks for the very fast answer. I''ve forgotten to say, that I use the
Express Edition - I think there is no Profiler. But when I call a bigger
procedure with some more insert and update commands I get the message that XX
rows has been affekted. So I think the procedure has been executed, because
the count of rows that has been affekted is similar to the count of update
and insert-commands I use in the peocedure, but nothing happens.

As output parameter I have defined @@identity and the number I get is also
the next one which normaly would been uses for the new row.

"Dave Sexton" wrote:

您好Jacek,


运行Sql Profiler并查看是否正在调用该过程。 Sql Profile

可以从企业管理器(Sql Server 2000)或Sql Server

Management Studio(Sql Server 2005)启动,两者都来自IIRC的工具菜单。 />

-

Dave Sexton


" J. S. EDV < JS *** @ discuss.microsoft.com写信息

news:86 ************************* ********* @ microsof t.com ...
Hi Jacek,

Run Sql Profiler and see if the procedure is being called at all. Sql Profile
can be launched from Enterprise Manager (Sql Server 2000) or Sql Server
Management Studio (Sql Server 2005), both from the Tools menu, IIRC.

--
Dave Sexton

"J. S. EDV" <JS***@discussions.microsoft.comwrote in message
news:86**********************************@microsof t.com...

您好,


我有存储过程和C#有点问题。


我有一个存储过程,只能在表中插入一些东西。

例如:


ALTER PROCEDURE DBO.PROC1

AS

插入dbo.Test值(''test'')

时,
。它做了它应该的程序过程在我的表中插入一行。

但如果我从C#执行它,它就不会。


SqlCommand cmd = new SqlCommand(" proc1",conn);

cmd.ExecuteNonQuery();


我收到1行已被记录的消息 - 但是表格中没有条目。


有没有人有一些想法我做错了什么?


谢谢!


Jacek
Hello,

I have got a little problem with stored procedures and C#.

I have got a stored procedure which should only insert something in a table.
For example:

ALTER PROCEDURE DBO.PROC1
AS
insert into dbo.Test values (''test'')

when I execute this procedure in my Visual Studio Envirment with right click
on it. It makes what it should The procedure inserts a row in my table.
But if I trie to execute it from C#, it doesn''t.

SqlCommand cmd = new SqlCommand("proc1",conn);
cmd.ExecuteNonQuery();

I get the message that 1 row has been affekted - but there is no entry in
the table.

Does anyone has some ideas what I have done wrong?

Thanks!

Jacek






你好Jacek,


听起来它正在工作,但你没有找到合适的地方进行验证。

如果你确保你刷新视图将表打开在Visual

Studio中。


您能以编程方式从数据库中提取新值吗?


-

Dave Sexton


" J. S. EDV < JS *** @ discuss.microsoft.com写信息

新闻:DC ************************* ********* @ microsof t.com ...
Hi Jacek,

It sounds like it''s working but your not looking at the right place to verify.
Make sure that you refresh the view if you have the table opened in Visual
Studio.

Can you programmatically extract the new values from the database?

--
Dave Sexton

"J. S. EDV" <JS***@discussions.microsoft.comwrote in message
news:DC**********************************@microsof t.com...

嗨Dave,


谢谢你非常快的答案。我忘了说,我使用的是

Express Edition - 我认为没有Profiler。但是当我用更多的插入和更新命令调用更大的

程序时,我得到的消息是

XX

行已经受到影响。所以我认为程序已经执行了,因为

已经受到影响的行数类似于更新的数量

和我在peocedure中使用的insert-commands但是没有任何反应。


作为输出参数,我定义了@@ identity,我得到的数字也是

下一个正常用于新行。


" Dave Sexton"写道:
Hi Dave,

thanks for the very fast answer. I''ve forgotten to say, that I use the
Express Edition - I think there is no Profiler. But when I call a bigger
procedure with some more insert and update commands I get the message that
XX
rows has been affekted. So I think the procedure has been executed, because
the count of rows that has been affekted is similar to the count of update
and insert-commands I use in the peocedure, but nothing happens.

As output parameter I have defined @@identity and the number I get is also
the next one which normaly would been uses for the new row.

"Dave Sexton" wrote:

>您好Jacek,
运行Sql Profiler并查看是否正在调用该过程。 Sql
配置文件
可以从企业管理器(Sql Server 2000)或Sql Server管理工作室(Sql Server 2005)启动,两者都来自工具菜单,IIRC。

-
Dave Sexton

J。 S. EDV < JS *** @ discussion.microsoft.com写信息
新闻:86 ***************************** ***** @ microso ft.com ...
>Hi Jacek,

Run Sql Profiler and see if the procedure is being called at all. Sql
Profile
can be launched from Enterprise Manager (Sql Server 2000) or Sql Server
Management Studio (Sql Server 2005), both from the Tools menu, IIRC.

--
Dave Sexton

"J. S. EDV" <JS***@discussions.microsoft.comwrote in message
news:86**********************************@microso ft.com...

您好,


我有一点问题存储过程和C#。


我有一个存储过程,只能在

表中插入一些东西。

例如:


ALTER PROCEDURE DBO.PROC1

AS

插入dbo.Test值(''test'')


当我在我的Visual Studio Envirment中执行此程序时,右键

点击

就可以了。它做了它应该的程序过程在我的表中插入一行。

但如果我从C#执行它,它就不会。


SqlCommand cmd = new SqlCommand(" proc1",conn);

cmd.ExecuteNonQuery();


我收到1行已被记录的消息 - 但是表格中没有条目。


有没有人有一些想法我做错了什么?


谢谢!


Jacek
Hello,

I have got a little problem with stored procedures and C#.

I have got a stored procedure which should only insert something in a
table.
For example:

ALTER PROCEDURE DBO.PROC1
AS
insert into dbo.Test values (''test'')

when I execute this procedure in my Visual Studio Envirment with right
click
on it. It makes what it should The procedure inserts a row in my table.
But if I trie to execute it from C#, it doesn''t.

SqlCommand cmd = new SqlCommand("proc1",conn);
cmd.ExecuteNonQuery();

I get the message that 1 row has been affekted - but there is no entry in
the table.

Does anyone has some ideas what I have done wrong?

Thanks!

Jacek







这篇关于C#和SQL-Server存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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