开发者

Issue inserting text into table from c# proc parameter

SqlConnection connection = new SqlConnection(cnnString);
try
{
    connection.Open();
    SqlCommand command = new SqlCommand("[dbo].[tblMessages_Insert]", connection);
    command.CommandType = CommandType.StoredProcedure;

    // params
    SqlParameter messageText = new SqlParameter("@messageText", SqlDbType.VarChar);
    messageText.Value = message;

    // add params
    command.Parameters.Add(messageText);

    rows = 开发者_如何学Gocommand.ExecuteNonQuery();
}

So this works, the row gets inserted, however, my message was "test message", and what ends up in the db is "t".

Whats happening?


did you give varchar a size in the proc..if you don't it will be 1 by default

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜