存储过程如下:
PROCEDURE [dbo].[Insert_Into_Reply] 
-- Add the parameters for the stored procedure here
(
@parent_id int,
@author varchar(50),
@content varchar(2000),
@add_date datetime
)
AS
BEGIN
insert into YanJiuReply values(@parent_id,@author,@content,@add_date)
update YanJiu set reply_count=reply_count+1,reply_date=@add_date where this_id=@parent_id
END如果在sql server里面执行存储过程是准确
但是在cs文件里面执行就出现错误提示"Insert_Into_Reply"附近有语法错误cs代码如下
string connStr = ConfigurationManager.AppSettings[0].ToString();
        SqlConnection conn = new SqlConnection(connStr);
        SqlCommand comm = new SqlCommand("Insert_Into_Reply", conn);
        comm.Parameters.AddWithValue("@parent_id",Convert.ToInt32(parentId));
        comm.Parameters.AddWithValue("@author",uName);
        comm.Parameters.AddWithValue("@content",content);
        comm.Parameters.AddWithValue("@add_date",DateTime.Now);
        conn.Open();
        try
        {
            comm.ExecuteNonQuery();
            conn.Close();
            return "s";
        }
        catch (SqlException ex)
        {
            conn.Close();
            return ex.Message;
        }请问这是什么原因呢?
恳请帮忙解决,非常感谢!
解决立即给分,在线等

解决方案 »

  1.   

    comm 的类型应该是存储过程.
      

  2.   

    SqlCommand comm = new SqlCommand("Insert_Into_Reply", conn);        comm.CommandType = CommandType.StoredProcedure;
      

  3.   

    SqlConnection conn = new SqlConnection(connStr);
    SqlCommand comm = new SqlCommand("Insert_Into_Reply", conn);你没说清楚是存储过程
    加上
    comm.CommandType = CommandType.StoredProcedure;
      

  4.   

    对,,他是一个储存过程,不是一条SQL语句
    所以要comm.CommandType = CommandType.StoredProcedure;
    指明为存储过程!
      

  5.   

    SqlConnection conn = new SqlConnection(connStr);
    SqlCommand comm = new SqlCommand("Insert_Into_Reply", conn);你没说清楚是存储过程
    加上
    comm.CommandType = CommandType.StoredProcedure;
    ----------------------------------------------------------
    如果不指定的话,会把“Insert_Into_Reply”当成SQL语句!
    CommandType 默认是 Text
      

  6.   

    加上:加上
    comm.CommandType = CommandType.StoredProcedure; // 执行类型为存储过程最后代码应改成如下更合理.防止conn.Open()有可能失败而没有捕获异常.
            try
            {
                conn.Open();
                comm.ExecuteNonQuery();
                return "s";
            }
            catch (SqlException ex)
            {
                return ex.Message;
            }
            finally
            {
                conn.Close();
            }