使用过程将C#插入两个表 [英] C# insert into two tables using a procedure

查看:92
本文介绍了使用过程将C#插入两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何使用过程将C#表单中的数据插入两个表中?我创建了以下过程:

Hello,

How can I insert data from a C# form into two tables using a procedure? I''ve created this procedure:

create or replace procedure insereaza
(den_furnizor varchar2, den_banca varchar2, explicate VARCHAR2, suma_facturata NUMBER) is
sqlstmt varchar2(4000);
begin

sqlstm:= insert into comanda (den_furnizor, den_banca)
          values (|| den_furnizor, den_banca||);
execute sqlstmt;
commit;

sqlstm:= insert into tabela2 (explicatie, suma_facturata)
values (|| explicate, suma_facturata||);

execute sqlstmt;
commit;

end insereaza;



但是我不知道如何从Windows窗体运行此存储过程.这些参数也是我表单中的文本框.



But I don''t know how I can run this stored procedure from my Windows Form. The parameters are also textbox in my form.

推荐答案

如果要使用ODBC,请参见
If you want to use ODBC, see here.


是的,您可以从添加了正确引用的任何.Net应用程序中调用存储过程.

具体来说,您需要查找SqlConnection,SqlCommand和SqlParameter类. Google是您的朋友.
Yes, you can call a stored procedure from any .Net app that has the correct references added to it.

Specifically, you need to look up the SqlConnection, SqlCommand, and SqlParameter classes. Google is your friend.


SqlConnection con = new SqlConnection("Specify ConnectionString");
con.open();
SqlCommand cmd =新的SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText =存储过程名称";
SqlParameter [] param =新的SqlParamter [4]; -定义参数大小
param [0] = new SqlParameter("@ ParamterName",textbox1.Text);
与Param [1],Param [2],Param [3]相同,..依此类推
cmd.Paramter.AddRange(param);
然后
int result = cmd.executenonquery();
那么如果插入结果,它将返回1.


希望对您有帮助.


谢谢

Lalit Kumar
印度
SqlConnection con=new SqlConnection("Specify ConnectionString");
con.open();
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="Stored Procedure Name";
SqlParameter[] param=new SqlParamter[4]; -- Define Parameter size
param[0]=new SqlParameter("@ParamterName",textbox1.Text);
same as Param[1],Param[2],Param[3], as.. so on
cmd.Paramter.AddRange(param);
then
int result=cmd.executenonquery();
then it will return 1 if result is inserted.


hope it will help u.


Thanks

Lalit Kumar
India


这篇关于使用过程将C#插入两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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