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 );
}
}