Set ansi_nulls on
Set quoted_identifier on
Go
Alter proc [DBO]. [GB] @ table_name
Varchar (8)
Declare @ SQL nvarchar (1000)
Set @ SQL = 'update' + @ table_name + 'set
Id = '+ '000000' + 'where id =' + '000000'
-- Set @ SQL = 'update' + 'aa' + 'set
Id = '+ '000000' + 'where id =' + '000000'
Exec sp_executesql @ SQL with recompile
The above is the use of dynamic SQL statements for Stored Procedures
Private void form1_load (Object sender,
Eventargs E)
{
Sqlconnection conn = new
Sqlconnection ("Server = localhost; database = example; uid = example; Pwd = example ");
Try
{
Conn. open ();
Label1.text = "connection successful! ";
}
Catch (exception ex)
{
Throw (Ex );
}
String SQL = "Exec select_table ";
Dataset DS = new dataset ();
Sqldataadapter da = new sqldataadapter (SQL, Conn );
Da. Fill (DS );
Datagridview1.datasource = Ds. Tables [0];
Textbox1.text = (string) datagridview1.currentcell. value;
Int ROW = This. datagridview1.currentcell. rowindex;
For (INT I = row; I <maid-1; I ++)
{
Conn. Close ();
Row = 0;
This. Maid = This. Maid [0, I];
Listbox1.items. Add (this. datagridview1.currentcell. value );
String mysql1 = "Exec GB", mysql2;
Mysql2 = (string) This. datagridview1.currentcell. value;
Mysql1 + = mysql2;
MessageBox. Show (mysql1 );
Sqlcommand cmd = new sqlcommand ("GB", Conn );
Cmd. commandtype = commandtype. storedprocedure;
Sqlparameter sp = new sqlparameter ("@ table_name ",
Sqldbtype. varchar, 8 );
Sp. value = mysql2;
Cmd. Parameters. Add (SP );
Conn. open ();
Cmd. executenonquery ();
Mysql2 = "";
}
Conn. Close ();
}
Executes the Stored Procedure cyclically. I finally finished it. Haha. In the future, use C # to develop the database. Haha ....