首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#net 将VARCHAR变换为int时出错

2012-11-10 
c#.net 将VARCHAR转换为int时出错点击右边红色标题查看本文完整版:c#.net 将VARCHAR转换为int时出错mycom.

c#.net 将VARCHAR转换为int时出错
点击右边红色标题查看本文完整版:c#.net 将VARCHAR转换为int时出错

mycom.Parameters.Add( "@Companyid ",System.Convert.ToInt32(L_compnay.Text.Trim()));//int型
mycom.Parameters.Add( "@Invest_adress ",T_Invest_adress.Text.ToString().Trim());
mycom.Parameters.Add( "@YcheckDate ",System.Convert.ToDatetime(T_ycheckDate.Text.Trim()));//datetime型
mycom.Parameters.Add( "@ServerDate ",T_ServerDate.Text.Trim());//datetime型
提交后提示:将VARCHAR转换为int时出错
另外下面的时间转换时也出错
要怎样解决?

------解决方法--------------------
类型不声明当然要报错

mycom.Parameters.Add( "@Companyid ", SqlDataType.Int32);
mycom.Parameters[ "@Companyid "].Value = System.Convert.ToInt32(L_compnay.Text.Trim());
mycom.Parameters.Add( "@Invest_adress ", SqlDataType.VarChar);
mycom.Parameters[ "@Invest_adress "].Value = T_Invest_adress.Text.ToString().Trim();
mycom.Parameters.Add( "@YcheckDate ", SqlDataType.DateTime);
mycom.Parameters[ "@YcheckDate "].Value = System.Convert.ToDatetime(T_ycheckDate.Text.Trim());

如果是 2.0,可以使用 AddWithValue() 方法,这样可以不用声明类型。

    

热点排行