开发者

Issue inserting text into table from c# proc parameter

开发者 https://www.devze.com 2023-02-22 02:44 出处:网络
SqlConnection connection = new SqlConnection(cnnString); try { connection.Open(); SqlCommand command = new SqlCommand(\"[dbo].[tblMessages_Insert]\", connection);
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

精彩评论

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