当前位置: 代码迷 >> ASP.NET >> 散分50请大家进来帮者指点看看!该怎么解决
  详细解决方案

散分50请大家进来帮者指点看看!该怎么解决

热度:688   发布时间:2013-02-26 00:00:00.0
散分50请大家进来帮者指点看看!!!
往数据库提交一条数据!因为我是新手想学习在.NET中如何使用存储过程!
更新数据储存过程名称:UP_carlhbvw_ADD
这三个变量是我定义的因为在页面中他们都是单选择按钮定义的组名
string   tg;
string   xb;
string   sr;
出错地方:myComm缺少命名空间但是我加了者两个空间了
using   System.Data.SqlClient;
using   System.Data;

还有者个地方出错说SqlDbType并不包含对varchar的定义!
这句话应该怎么写呢??
myComm.Parameters.Add   (new   SqlParameter( "@car_name ",SqlDbType.varchar,10));

( "@数据库字段名称 ",SqlDbType.数据库字段类型,长度));
不是这样吗?

————————————————————————————
我的源码:
private   void   tj_Click(object   sender,   System.EventArgs   e)
{
string   tg;
string   xb;
string   sr;
SqlConnection   con=carlhb.createConnection();
con.Open();
SqlCommand   cmd   =   new   SqlCommand();
string   UP_carlhbvw_ADD= "insert   into   ztlArretComment(car_1,tg,car_wx,xb,car_2,car_dq1,car_dq2,car_3,car_4,car_5,car_6,sr,car_7)   values   (@car_name,@car_tgb,@car_service,@car_sex,@car_abbress,@car_areaa,@car_areab,@car_tel,@car_mobile,@car_email,@car_msnqq,@car_income,@car_description) ";
cmd.CommandText= "UP_carlhbvw_ADD ";
cmd.CommandType=CommandType.StoredProcedure;

myComm.Parameters.Add   (new   SqlParameter( "@car_name ",SqlDbType.varchar,10));
cmd.Parameters[ "@car_name "].Value   =   car_1;

myComm.Parameters.Add   (new   SqlParameter( "@car_tgb ",SqlDbType.varchar,10));
cmd.Parameters[ "@car_tgb "].Value   =   tg;

myComm.Parameters.Add   (new   SqlParameter( "@car_service ",SqlDbType.varchar,10));
cmd.Parameters[ "@car_service "].Value   =   car_wx;

myComm.Parameters.Add   (new   SqlParameter( "@car_sex ",SqlDbType.varchar,5));
cmd.Parameters[ "@car_sex "].Value   =   xb;

myComm.Parameters.Add   (new   SqlParameter( "@car_address ",SqlDbType.varchar,100));
cmd.Parameters[ "@car_address "].Value   =   car_2;

myComm.Parameters.Add   (new   SqlParameter( "@car_areaa ",SqlDbType.varchar,30));
cmd.Parameters[ "@car_areaa "].Value   =   car_dq1;

myComm.Parameters.Add   (new   SqlParameter( "@car_areab ",SqlDbType.varchar,30));
cmd.Parameters[ "@car_areab "].Value   =   car_dq2;

myComm.Parameters.Add   (new   SqlParameter( "@car_tel ",SqlDbType.varchar,30));
cmd.Parameters[ "@car_tel "].Value   =   car_3;

myComm.Parameters.Add   (new   SqlParameter( "car_mobile ",SqlDbType.varchar,30));
cmd.Parameters[ "@car_mobile "].Value   =   car_4;

myComm.Parameters.Add   (new   SqlParameter( "@car_email ",SqlDbType.varchar,50));
cmd.Parameters[ "@car_email "].Value   =   car_5;

myComm.Parameters.Add   (new   SqlParameter( "@car_msnqq ",SqlDbType.varchar,50));
cmd.Parameters[ "@car_msnqq "].Value   =   car_6;

myComm.Parameters.Add   (new   SqlParameter( "@car_income ",SqlDbType.varchar,10));
cmd.Parameters[ "@car_income "].Value   =   sr;

myComm.Parameters.Add   (new   SqlParameter( "@car_description ",SqlDbType.varchar,200));
cmd.Parameters[ "@car_description "].Value   =   car_7;

cmd.ExecuteNonQuery();
con.Close();
}

------解决方案--------------------------------------------------------
  相关解决方案