SQL code
Create procedure 'yuan _ user_cc '(in xname varchar (100), in xemail varchar (100), in xpassword varchar (100), out xid integer)
Begin
Insert into yuan_user (name, email, password) values (xname, xemail, xpassword );
Select id into xid from yuan_user where name = xname;
End
C # code
Private string shuju_lianjie (string name, string email, string password)
{
Int16 id; // The returned id.
MySqlConnection mysqlcon;
MySqlDataAdapter mysqldata = new MySqlDataAdapter ();
DataSet dataset = new DataSet ();
Mysqlcon = new MySqlConnection ("server = localhost; user id = root; password = 123; database = yuan_test; pooling = false; charset = gb2312 ");
Mysqldata. SelectCommand = new MySqlCommand ();
Mysqldata. SelectCommand. Connection = mysqlcon;
Mysqldata. SelectCommand. CommandText = "yuan_user_cc ";
Mysqldata. SelectCommand. CommandType = CommandType. StoredProcedure;
// Set parameters and add them to the database
MySqlParameter name_parameter = new MySqlParameter ("? Xname ", MySqlDbType. VarChar, 100); // What is the Stored Procedure Parameter of mysql? Headers !!!!
Name_parameter.Value = name;
Mysqldata. SelectCommand. Parameters. Add (name_parameter );
// ++ ++
MySqlParameter email_parameter = new MySqlParameter ("? Xemail ", MySqlDbType. VarChar, 100); // What is the Stored Procedure Parameter of mysql? Headers !!!!
Email_parameter.Value = email;
Mysqldata. SelectCommand. Parameters. Add (email_parameter );
// ++ ++
MySqlParameter password_parameter = new MySqlParameter ("? Xpassword ", MySqlDbType. VarChar, 100); // What is the Stored Procedure Parameter of mysql? Headers !!!!
Password_parameter.Value = password;
Mysqldata. SelectCommand. Parameters. Add (password_parameter );
// ++ Return value ++ ++
MySqlParameter id_parameter = new MySqlParameter ("? Xid ", MySqlDbType. Int16, 15); // What is the Stored Procedure Parameter of mysql? Headers !!!!
Id_parameter.Direction = ParameterDirection. Output;
Mysqldata. SelectCommand. Parameters. Add (id_parameter );
// ++ Open the database and insert data, returns the id value +++ ++
Try
{
Mysqldata. Fill (dataset, "yuan_user_cc ");
Id = (Int16) id_parameter.Value;
Return id. ToString ();
}
Catch (MySqlException ex)
{
MessageBox. Show (ex. Message );
Return String. Empty;
}
}