Stored Procedure Application

Source: Internet
Author: User

Create proc modify
(@ No. [int],
@ Name [varchar] (50 ),
@ Phone number [varchar] (50)
)
As
Insert into pro (stuid, stuname, stuphone) values (@ number, @ name, @ phone number)
Go

Create proc UPD
(@ No. [int],
@ Name [varchar] (50 ),
@ Phone number [varchar] (50)
)
As
Update pro set stuid = @ No., stuname = @ name, stuphone = @ phone where (stuid = @ No)
Go
Create proc del
(
@ No. [int]
)
As
Delete pro where ([stuid] = @ number)

 

 

Namespace Stored Procedure
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Sqldataadapter SDA = new sqldataadapter ();
SDA. selectcommand = new sqlcommand ("getall", con );
SDA. selectcommand. commandtype = commandtype. storedprocedure;
Dataset DS = new dataset ();
SDA. Fill (DS );
Datagridview1.datasource = Ds. Tables [0]. defaultview;
}

Private void button2_click (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("modify", con );
Cmd. commandtype = commandtype. storedprocedure;
Sqlparameter [] prams = {New sqlparameter ("@ ID", sqldbtype. INT), new sqlparameter ("@ name", sqldbtype. varchar, 50), new sqlparameter ("@ phone", sqldbtype. varchar, 50 )};
Prams [0]. value = ID. text;
Prams [1]. value = Name. text;
Prams [2]. value = phone. text;
Foreach (sqlparameter Pa in prams)
{
Cmd. Parameters. Add (PA );
}
Cmd. executenonquery ();
// This. Load (sender, e );
This. button#click (sender, e );
}

Private void form1_load (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select stuid from Pro", con );
Sqldatareader SDR = cmd. executereader ();
While (SDR. Read ())
{
Combobox1.items. Add (SDR ["stuid"]. tostring ());
}
}

Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Int I = convert. toint32 (combobox1.selecteditem );
Sqlcommand cmd = new sqlcommand ("select * from Pro where stuid = '" + I + "'", con );
Sqldatareader SDR = cmd. executereader ();
SDR. Read ();
Textbox1.text = SDR ["stuname"]. tostring ();
Textbox2.text = SDR ["stuphone"]. tostring ();
// While (SDR. Read ())
//{

//}
}

Private void button3_click (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("UPD", con );
Cmd. commandtype = commandtype. storedprocedure;
Sqlparameter [] prams = {New sqlparameter ("@ ID", sqldbtype. INT), new sqlparameter ("@ name", sqldbtype. varchar, 50), new sqlparameter ("@ phone", sqldbtype. varchar, 50 )};
Prams [0]. value = combobox1.text;
Prams [1]. value = textbox1.text;
Prams [2]. value = textbox2.text;
Foreach (sqlparameter SP in prams)
{
Cmd. Parameters. Add (SP );
}
Cmd. executenonquery ();
Button#click (sender, e );
}

Private void button4_click (Object sender, eventargs E)
{
Sqlconnection con = dB. createcon ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("Del", con );
Cmd. commandtype = commandtype. storedprocedure;
Sqlparameter sp = new sqlparameter ("@ number", sqldbtype. INT );
Cmd. Parameters. Add (SP );
Cmd. Parameters ["@ No."]. value = combobox1.text;
Cmd. executenonquery ();
Button#click (sender, e );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.