首页 新闻 搜索 专区 学院

字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据

0
[已解决问题] 解决于 2011-01-28 10:37

string OleDb = "INSERT INTO [User]([UserName],[UserLoginID],[UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Email],[Business],[Photo]) VALUES('@UserName','@UserLoginID','@UserLoginPassword','@Sex','@Organization','@Address','@Telphone','@Email','@Business','@Photo')";
   
   try
   {
    OleDbParameter[] para = new OleDbParameter[]
    {
                    new OleDbParameter("@UserName",user.UserName),
                    new OleDbParameter("@UserLoginID",user.UserLoginID),
                    new OleDbParameter("@UserLoginPassword",user.UserLoginPassword),
                    new OleDbParameter("@Sex",user.Sex),
                    new OleDbParameter("@Organization",user.Organization),
     new OleDbParameter("@Address",user.Address),
                    new OleDbParameter("@Telphone",user.Telphone),
                    new OleDbParameter("@Email",user.Email),
                    new OleDbParameter("@Business",user.Business),
     new OleDbParameter("@Photo",user.Photo),
                   
     
    };

    int i=DBHelper.ExecuteCommand(OleDb, para);

                return i == 1 ? true : false;
   }
   catch (Exception e)
   {
    Console.WriteLine(e.Message);
    throw e;
   }

System.Data.OleDb.OleDbException: 查询值的数目与目标字段中的数目不同。

九妹的主页 九妹 | 初学一级 | 园豆:167
提问于:2011-01-27 21:39
< >
分享
最佳答案
0

string OleDb = "INSERT INTO [User]([UserName],[UserLoginID],[UserLoginPassword],[Sex],[Organization],[Address],[Telphone],[Email],[Business],[Photo]) VALUES(''@UserName'',''@UserLoginID'',''@UserLoginPassword'',''@Sex'',''@Organization'',''@Address'',''@Telphone'',''@Email'',''@Business'',''@Photo'')";

//即将所有的单引号替换为两个单引号

 

邀月 | 高人七级 |园豆:25375 | 2011-01-28 08:50
这是why?
massinger | 园豆:706 (小虾三级) | 2011-01-28 09:32
@massinger:你那个语句实际上有语法错误,无法执行!
邀月 | 园豆:25375 (高人七级) | 2011-01-30 08:28
其他回答(2)
0

表面上看少了photo,代码不完整,看不出来啊。

massinger | 园豆:706 (小虾三级) | 2011-01-27 22:14
0

我看了一下,是不是楼主写参数数组的时候多了一个逗号呀, try
   {
    OleDbParameter[] para = new OleDbParameter[]
    {
                    new OleDbParameter("@UserName",user.UserName),
                    new OleDbParameter("@UserLoginID",user.UserLoginID),
                    new OleDbParameter("@UserLoginPassword",user.UserLoginPassword),
                    new OleDbParameter("@Sex",user.Sex),
                    new OleDbParameter("@Organization",user.Organization),
     new OleDbParameter("@Address",user.Address),
                    new OleDbParameter("@Telphone",user.Telphone),
                    new OleDbParameter("@Email",user.Email),
                    new OleDbParameter("@Business",user.Business),
     new OleDbParameter("@Photo",user.Photo),
                    
     
    };

就是最后那个参数new OleDbParameter("@Photo",user.Photo),  那个后面应该是多余的吧,

万法归一 | 园豆:57 (初学一级) | 2011-01-28 10:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册