访问和C#.net更新问题 [英] Access and C#.net Update Problem

查看:50
本文介绍了访问和C#.net更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int val = 0;
                OleDbCommand cmdUpdateCommand = new OleDbCommand("Update LineDetails set Shift=?, LineNumber=?, Active=?, NoPlan=?, OOS=?, Cleaning=?, NoMan=?, OOSDetails=?, [Date]=? where Shift=?", conn);

                cmdUpdateCommand.Parameters.Add("Shift", OleDbType.Char).Value = dgvLineDetails.CurrentRow.Cells["Shift"].Value;
                cmdUpdateCommand.Parameters.Add("LineNumber", OleDbType.Integer).Value = dgvLineDetails.CurrentRow.Cells["LineNumber"].Value;
                cmdUpdateCommand.Parameters.Add("Active", OleDbType.Boolean).Value = dgvLineDetails.CurrentRow.Cells["Active"].Value;
                cmdUpdateCommand.Parameters.Add("NoPlan", OleDbType.Boolean).Value = dgvLineDetails.CurrentRow.Cells["NoPlan"].Value;
                cmdUpdateCommand.Parameters.Add("OOS", OleDbType.Boolean).Value = dgvLineDetails.CurrentRow.Cells["OOS"].Value;
                cmdUpdateCommand.Parameters.Add("Cleaning", OleDbType.Boolean).Value = dgvLineDetails.CurrentRow.Cells["Cleaning"].Value;
                cmdUpdateCommand.Parameters.Add("NoMan", OleDbType.Boolean).Value = dgvLineDetails.CurrentRow.Cells["NoMan"].Value;
                cmdUpdateCommand.Parameters.Add("OOSDetails", OleDbType.Char).Value = dgvLineDetails.CurrentRow.Cells["OOSDetails"].Value;
                cmdUpdateCommand.Parameters.Add("Date", OleDbType.Date).Value = dgvLineDetails.CurrentRow.Cells["Date"].Value;

                conn.Open();
                val = cmdUpdateCommand.ExecuteNonQuery();
                if (val > 0)
                {
                    MessageBox.Show("Shift Updated");
                }
                conn.Close();



当我使用上述代码进行更新时,它给出了异常没有为一个或多个参数提供任何值.任何人都可以帮助我解决问题.紧急.今天是我的项目截止日期....非常感谢



when i m updating using above code Its gives exception No value given for one or more paramaeter. Anyone can help me how to solve it. Urgent.. Today is my project deadline.... Thanks a lot

推荐答案

今天是我的项目截止日期
谁给狗屎!你以为有人会睡一觉吗?那是你的问题.

提示:检查您的参数列表,即?"以及传递的值数.想想最后一个,是吧?

在此消息和收到的错误消息之间,有很多线索可以让您自己找出原因,呵呵:doh:
Today is my project deadline
who gives a shite! you think anyone will loose a sleep? That is your problem.

Hint: Check your parameter list i.e "?" and the number of values passed. Think the last one, huh?

Between this and the error message you got, there is plenty of clue for you to figure it out on your own, huh :doh:


因为您使用的是?"参数化查询,即使重复输入,也需要提供所有参数.因此缺少一个参数值供应.

如果您在查询中使用Shift = @Shift等等.
然后
cmdUpdateCommand.Parameters.Add("@ Shift",OleDbType.Char)...

这对您应该有用,因为Shift是将被使用两次且一次提供值就足够的参数.
有关示例示例,请看这里:
在ASP.Net中使用参数化查询 [
Since you are using ''?'' as the parametrized query, you need to give all the parameters, even though if it is repeated. Thus one parameter value supply is missing.

If you use Shift = @Shift and so...in query.
and then
cmdUpdateCommand.Parameters.Add("@Shift", OleDbType.Char)...

this should work for you as Shift is the parameter that will be used twice and supplying value once would be enough.
For sample example, look here:
Using Parameterized Queries in ASP.Net[^]


这篇关于访问和C#.net更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆