CREATE proc SetCallBoardMessage(@msg varchar(1000))--创建加入公告存储过程
as insert into getmsg values (@msg,getdate())
GO这是一个插入公告的存储过程
当我那个里面有空格或者是有标点符号的时候就报错
请问一下是什么原因

解决方案 »

  1.   

    @msg的内容里有 空格或者 标点符号报错么?那应该和你的程序调用有关,这个存储执行是没有问题的
      

  2.   

    那程序调用应该怎么写咧
    这个是我写的db.SetMessage(TextBoxMsg.Text.ToString().Trim());
      

  3.   

    但是他确实是报错了
    我就写了hello word!这个词
    第 1 行: 'word' 附近有语法错误。
      

  4.   

    --創建測試環境
    Create Table getmsg(msg Varchar(100), msgDate DateTime)
    GO
    --創建存儲過程
    CREATE proc SetCallBoardMessage(@msg varchar(1000))--创建加入公告存储过程
    as insert into getmsg values (@msg,getdate())
    GO
    --測試
    EXEC SetCallBoardMessage 'hello word!'Select * From getmsg
    GO
    --刪除測試環境
    Drop Table getmsg
    Drop proc SetCallBoardMessage
    --結果
    /*
    msg msgDate
    hello word! 2007-08-09 17:24:56.820
    */
      

  5.   

    是不是我在前面调用那样写不行啊
    谢谢你了
    db.SetMessage(TextBoxMsg.Text.ToString().Trim());
    这是调用的
      

  6.   

    public static bool SetMessage(string msg)
    {
    SqlConnection con = CreateConnection();
    SqlCommand cmd = new SqlCommand("SetCallBoardMessage "+ msg ,con);
    con.Open();
    int ret = cmd.ExecuteNonQuery();
    con.Close();

    if(ret != 0)
    return true;
    else
    return false;
    }
      

  7.   

    SqlCommand cmd = new SqlCommand("SetCallBoardMessage "+ msg ,con);------------
    這裡的問題
      

  8.   

    SqlConnection con = CreateConnection();
    SqlCommand cmd = new SqlCommand("SetCallBoardMessage "+ msg ,con);改為SqlConnection con = CreateConnection();
    SqlCommand cmd = new SqlCommand();
    sqlCmd.CommandText = "SetCallBoardMessage";
    sqlCmd.CommandType = CommandType.StoredProcedure;
    sqlCmd.Parameters.Add("@msg", msg);