尝试从网页插入我的数据库但是显示一条错误消息,表明插入的值无法传递到数据库,并且在调试错误消息之后我很清楚“insertforum”存储过程不能是找到。如何解决这个问题呢?
public class PostForum
{
public static int insertForum(int titleid, string question, string posterName, DateTime datetime, string username)
{
int rowsAffected = 0;
using (SqlConnection connection = ConnectionManager.GetDatabaseConnection())
{
SqlCommand cmmand = new SqlCommand("insertForum", connection);
cmmand.CommandType = CommandType.StoredProcedure;
cmmand.Parameters.Add("@titleid", SqlDbType.Int).Value = titleid;
cmmand.Parameters.Add("@question", SqlDbType.VarChar).Value = question;
cmmand.Parameters.Add("@posterName", SqlDbType.VarChar).Value = posterName;
cmmand.Parameters.Add("@datetime", SqlDbType.DateTime).Value = datetime;
cmmand.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
cmmand.ExecuteNonQuery();
}
return rowsAffected;
}
}
这是我的连接字符串:
<connectionStrings>
<add name="nn008ConnectionString" connectionString="Data Source=SQL-SERVER;Initial Catalog=nn008;Integrated Security=True"
providerName="System.Data.SqlClient" />
答案 0 :(得分:0)
我只是在management studio上为insertForum创建了一个存储过程,并修复了错误。以下是我如何解决错误:
CREATE PROCEDURE insertForum ( @titleid int, @question varchar(200), .......... ......... ) 如 INSERT论坛 ( titleid, 题, ....... ....... ) 值 ( titleid, 题, ........ ....... ) RETURN