日期:2014-05-19  浏览次数:20978 次

System.Data.OleDb.OleDbException: 标准表达式中数据类型不匹配
错误提示:System.Data.OleDb.OleDbException:   标准表达式中数据类型不匹配。   at   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32   hr)   at   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS   dbParams,   Object&   executeResult)   at   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&   executeResult)   at   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior   behavior,   Object&   executeResult)   at   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior   behavior,   String   method)   at   System.Data.OleDb.OleDbCommand.ExecuteNonQuery()   at   HooYon.newsadd.Output_Click(Object   sender,   EventArgs   e)   in   e:\web   server\hooyon\newsadd.aspx.cs:line   93    
源代码:
Conn_Access   Link   =   new   Conn_Access();//连接数据库
string   sql   =   "insert   into   HY_ZiXun   (HY_ZXTitle,HY_ZXInfo,HY_ZXTJR,HY_ZXType,HY_ZXLY)   values   (@Title,@Content,@Author,@Type,@Comefrom) ";
OleDbCommand   cmm   =   new   OleDbCommand(sql,Link.Conn);//实例化
Link.Access_Open();//打开连接
try
{
OleDbParameter   titl   =   new   OleDbParameter( "@Title ",OleDbType.VarChar,0);
titl.Value   =   Server.HtmlEncode(topic.Text);
cmm.Parameters.Add(titl);

OleDbParameter   zuozhe   =   new   OleDbParameter( "@Author ",OleDbType.VarChar,0);
zuozhe.Value   =   Server.HtmlEncode(author.Text);
cmm.Parameters.Add(zuozhe);

OleDbParameter   num   =   new   OleDbParameter( "@Type ",OleDbType.Integer,0);
num.Value   =   Convert.ToInt32(DropDownList1.SelectedItem.Value);
cmm.Parameters.Add(num);

OleDbParameter   neirong   =   new   OleDbParameter( "@Content ",OleDbType.VarChar,0);
neirong.Value   =FreeTextBox1.Text;
cmm.Parameters.Add(neirong);

OleDbParameter   from   =   new   OleDbParameter( "@Comefrom ",OleDbType.VarChar,0);
from.Value   =   Server.HtmlEncode(From.Text);
cmm.Parameters.Add(from);

cmm.ExecuteNonQuery();//出错行
Link.Access_Close();
Response.Write( " <script> javascript:alert( '恭喜!数据添加成功! '); </script> ");
Response.Write( " <script> javascript:window.location= 'newsadd.aspx '; </script> ");
}
catch(Exception   err)
{
Link.Access_Close();
Response.Write(err.ToString());
// Response.Write( " <script> javascript:alert( 'Sorry!数据添加失败! '); </script> ");
}

------解决方案--------------------
sql语句的问题
------解决方案--------------------
在数据库里这几个字段的类型也是varchar varchar integer varchar varchar吗?
还有( "@Title ",OleDbType.VarChar,0);第三个参数是参数的大小,你为什么都写的是0呢?
------解决方案--------------------
确切地说是sql语句的语法错误;

为什么你的所有参数长度都是0?
------解决方案--------------------
顶楼上
------解决方案--------------------
不加第三个参数试试看?