日期:2014-05-18  浏览次数:20425 次

请教,下面这段代码为什么出现 CS201错误呢?网速慢,搜索了麻烦啊,恳请大家指教
SqlConnection   conn   =   new   SqlConnection( "server=(local); "+ "Database=bbs; "+ "Integrated   Security=true; ");
               

                SqlCommand   cmd   =   new   SqlCommand();
                cmd.CommandText   =   "INSERT   INTO   post(name,subject,message,[date],ip)   Values   (   ' ";   strName   +   " ', ' "   +   strSubject   +   " '. ' "   +   strMsg   +   " ', ' "   +   strDate   +   " ', ' "   +   strIP   +   " '); ";
                cmd.Connection   =   conn;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();

------解决方案--------------------
try:
cmd.CommandText = "INSERT INTO post(name,subject,message,[date],ip) Values ( ' "+ strName + " ', ' " + strSubject + " ', ' " + strMsg + " ', ' " + strDate + " ', ' " + strIP + " ') ";