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
精彩评论