Parameter value

J

Jim McGivney

I have a button on an aspx page. When the user clicks the button I would
like to add a new row to an existing table in my Access database. The table
is Ante_Admin. The name of the key field is AnteNum, I would like to set
the value of AnteNum to MyVal.

In code behind on an aspx page I have:

protected void Button1_Click1(object sender, EventArgs e)

{

string MyVal = "2";

AccessDataSource AccessDataSource2 = new AccessDataSource();

AccessDataSource2.DataFile =
System.Configuration.ConfigurationManager.AppSettings["ConnString"];


Parameter Param = new Parameter("AnteNum");

Param.DefaultValue = MyVal;

AccessDataSource2.SelectParameters.Add(Param);

AccessDataSource2.InsertCommand = "INSERT INTO Ante_Admin (AnteNum) VALUES
(@Param)";

AccessDataSource2.Insert();

}

When the button is pressed, I get the following error message: No value
given for one or more required parameters.

This probably exhibits my lack of understanding of Parameters. I am not
able to set the value of Param to MyVal. Any suggestions including sample
code would be appreciated.

Jim
 
S

sendtobiren

Try replaceing @Param with (?) in the Insert command you are
passing......

I am sure it will work.
 
H

Hans Kesting

I have a button on an aspx page. When the user clicks the button I would
like to add a new row to an existing table in my Access database. The table
is Ante_Admin. The name of the key field is AnteNum, I would like to set the
value of AnteNum to MyVal.

In code behind on an aspx page I have:

protected void Button1_Click1(object sender, EventArgs e)

{

string MyVal = "2";

AccessDataSource AccessDataSource2 = new AccessDataSource();

AccessDataSource2.DataFile =
System.Configuration.ConfigurationManager.AppSettings["ConnString"];


Parameter Param = new Parameter("AnteNum");

Param.DefaultValue = MyVal;

AccessDataSource2.SelectParameters.Add(Param);

AccessDataSource2.InsertCommand = "INSERT INTO Ante_Admin (AnteNum) VALUES
(@Param)";

AccessDataSource2.Insert();

}

When the button is pressed, I get the following error message: No value given
for one or more required parameters.

This probably exhibits my lack of understanding of Parameters. I am not able
to set the value of Param to MyVal. Any suggestions including sample code
would be appreciated.

Jim

This is also a standard Access way of saying "I don't know that column
you specified". Does "AnteNum" really exist (typo somewhere?)

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,272
Latest member
MaricruzDu

Latest Threads

Top