我的数据表有个字段是记录一个CheckBoxList的值的,类型是char(15)型,我在记录到数据库的时候做了处理,都已'1,2,3,4'存入,1,2,3,4 分别是每个CheckBoxList.Item[i].value,也是数据库另外一个表的相应ID号(int),代表一个类别的编号.然后我要在另一个页面上把这些值(1,2,3,4)用那个有ID字段的表中name(char型)字段还原显示出来,有没有一个select语句直接实现? select ID,name where ID in '1,2,3,4'?我记得 有 delete * from tablename where ID in ****,如果没有,有什么替代的办法吗?
---------------------------------------表现层----------------------------------------
***.text=DisplayType('1,2,3')
public string DisplayType(string getchar)
{string Type;
GF Dis = new GF();//GF是封装DisplayType方法的类
SqlDataReader Kind = Dis.DisplayType(getchar);
if (Kind.Read())
{Type="";
while(Kind.Read())
{
                     Type+=" "+Kind["CorpKindName"].ToString();
}
}
else
Type="";
        return Type;
}
-----------------------------------------业务层----------------------------------------
public SqlDataReader DisplayType(string CorpKind)
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("GetCorpKind",myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterCorpKind = new SqlParameter("@CorpKind",SqlDbType.Char,15);
parameterCorpKind.Value= CorpKind;
myCommand.Parameters.Add(parameterCorpKind);
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return result;

}
----------------------------------------数据层----------------------------------------------
CREATE PROCEDURE GetCorpKind
@CorpKind  char(15)
AS
Select CorpKindName
FROM CorpKindType
WHERE CorpKindID in (@CorpKind)
GO
这是我想的 我用查询分析器的时候exec GetCorpKind 1 可以的 用exec GetCorpKind 1,2 说参数太多,用上面的code执行的时候,没有返回值,就是***.text=""最后,但事跟踪器中有执行 exec GetCorpKind @CorpKind = '2              ',然后我按照exec GetCorpKind @CorpKind = '2,3',系统报错服务器: 消息 245,级别 16,状态 1,过程 GetCorpKind,行 4
将 varchar 值 '2,3            ' 转换为数据类型为 tinyint 的列时发生语法错误。