Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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

SQL
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;


But I don't know how I can run this stored procedure from my Windows Form. The parameters are also textbox in my form.
Posted
Updated 26-May-10 5:44am
v4

If you want to use ODBC, see here.
 
Share this answer
 
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.
 
Share this answer
 
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
 
Share this answer
 
Comments
Husain Ahmad Khalid 27-May-10 5:28am    
Sorry Kumar Jee,

Your code will not work for him, he is not using Microsoft SQL Server, if you can observe from his code probably he is using MySql, so instead of SqlConnection class he can use MySqlConnection class which is a separate library and he can download it from http://www.mysql.com

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900