我希望从mysql数据库文件中选择id为2,4,6的记录数组。我试图将一个整数数组传递给一个Mysql存储过程。但是我无法创建一个工作存储过程。如何将参数数组传递给MySql select ... in
你能帮我写作吗?
这是C#代码
public static List<PhotoComment> GetPhotos(int[] _ids)
{
MySqlConnection _con = Generals.GetConnnection();
List<PhotoComment> _comments = new List<PhotoComment>();
try
{
MySqlCommand _cmd = new MySqlCommand("Photos_GetPhotosByIDs", _con);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.AddWithValue("@_ids", _ids);
_con.Open();
MySqlDataReader _reader = _cmd.ExecuteReader();
while (_reader.Read())
{
PhotoComment _comment = new PhotoComment(_reader.GetInt32("cID"), _reader.GetInt32("cFID"), _reader.GetString("cUser"), _reader.GetString("cContent"), _reader.GetDateTime("cDate"), _reader.GetBoolean("cChecked"));
_comments.Add(_comment);
}
_con.Close();
}
catch (Exception _ex)
{
_con.Close();
ReportMgr.ReportException(_ex.Message);
}
return _comments;
}
这是MySQL
CREATE DEFINER = root
@localhost
PROCEDURE Photos_GetPhotosByIDs
(在_ids INT [])
BEGIN
选择*从tbl_photos其中ID在ID中;
END
你可以与我们分享任何代码? –