473,486 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Update Error in VS2005 with MS Access

The following code in VS2005 with MS Access 2003 gives me an error : “No
Value given for one or more required parameters”
What am I doing wrong?

string sconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\\Mydatabase.mdb";
string squeryString = "UPDATE MyTable SET Col1 = ?,Col2 = ?
WHERE ColId = ?";

int num = 19;
string str2 = txtRep.Text;
string str3 = txtCompanyName.Text;

try
{
using (OleDbConnection con = new
OleDbConnection(sconnectionString))
{
using (OleDbCommand cmd = new OleDbCommand(squeryString,
con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Col1", str2);
cmd.Parameters.AddWithValue("Col2", str3);
cmd.Parameters.AddWithValue("ColId", num);

con.Open();
cmd.ExecuteNonQuery();
}
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Oct 10 '08 #1
1 1258
Nevermind, there was a typo in one of the fields causing the error.

"Rick" wrote:
The following code in VS2005 with MS Access 2003 gives me an error : “No
Value given for one or more required parameters”
What am I doing wrong?

string sconnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\\Mydatabase.mdb";
string squeryString = "UPDATE MyTable SET Col1 = ?,Col2 = ?
WHERE ColId = ?";

int num = 19;
string str2 = txtRep.Text;
string str3 = txtCompanyName.Text;

try
{
using (OleDbConnection con = new
OleDbConnection(sconnectionString))
{
using (OleDbCommand cmd = new OleDbCommand(squeryString,
con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Col1", str2);
cmd.Parameters.AddWithValue("Col2", str3);
cmd.Parameters.AddWithValue("ColId", num);

con.Open();
cmd.ExecuteNonQuery();
}
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Oct 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5239
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
5
3513
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
1
2463
by: Scott F K Hooper | last post by:
VB.NET 2.0 project... I have an Access database with a table that has one primary key. I have used the Add TableAdapter wizard in VS2005 to create my TableAdapter. Next I added an ObjectDataSource...
30
3349
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
0
4714
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
2
2177
by: TimR | last post by:
I am trying to create my first Web application in VS2005 and am pulling my hair out!!!! I cannot seem to get aspx pages to work from a locally installed copy of IIS. I am getting a...
0
1457
by: JDS | last post by:
I have a table with the primary key as a uniqueidentifier / GUID and the rowguid property set (it is used for replication). When creating a data table in a dataset in VS2005 the table adapter...
1
3347
by: Bob | last post by:
Hello, I'm in a real predicament. I built up a new 64bit PC due to a virus and a flaky hard drive. Installed all my programs (Excel, Word, VS2005, etc) all the programs worked except for the VB...
0
7099
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.