Using VS'05 I have a label (LabelFileNum) on an aspx page. I want to set
the text of the lable to the last name, which is a field from a table called
Ante_pedigree from an Access Database.
I use the C# code-behind:
OleDbConnection dbConn = null;
OleDbCommand dCmd = null;
string strConn = null;
string strSQL = null;
// Open data connaction to get name info
strConn =
System.Configuration.ConfigurationManager.AppSettings["oledbConnStr"];
dbConn = new OleDbConnection(strConn);
dbConn.Open();
//Initialize label
LabelFileNum.Text = "";
// Get the last
strSQL = "SELECT LastName FROM Ante_Pedigree Where @dotnet.itags.org.AnteNum = ?";
dCmd = new OleDbCommand(strSQL, dbConn);
dCmd.Parameters.AddWithValue("@dotnet.itags.org.AnteNum", OleDbType.Char).Value = fileid;
LabelFileNum.Text = LabelFileNum.Text + " " +
dCmd.ExecuteScalar().ToString();
I get the error "No value given for one or more required parameters."
Any suggestions ? This similar code worked in asp.net 1.1
Thanks,
JimI've seen some strange results from lines like:
> dCmd.Parameters.AddWithValue("@.AnteNum", OleDbType.Char).Value = fileid;
try breaking it into two lines as you are actually trying to accomplish two
tasks:
dCmd.Parameters.AddWithValue("@.AnteNum", OleDbType.Char);
dCmd.Parameters["@.AnteNum"].Value = fileid;
(or at least I think that's the syntax)
That may help,
Trevor Braun
"Jim McGivney" <mcgiv1@.no-spam.sbcglobal.net> wrote in message
news:eD5VcsbYGHA.5004@.TK2MSFTNGP02.phx.gbl...
> Using VS'05 I have a label (LabelFileNum) on an aspx page. I want to set
> the text of the lable to the last name, which is a field from a table
> called Ante_pedigree from an Access Database.
> I use the C# code-behind:
>
> OleDbConnection dbConn = null;
> OleDbCommand dCmd = null;
> string strConn = null;
> string strSQL = null;
>
> // Open data connaction to get name info
> strConn =
> System.Configuration.ConfigurationManager.AppSettings["oledbConnStr"];
> dbConn = new OleDbConnection(strConn);
> dbConn.Open();
>
> //Initialize label
> LabelFileNum.Text = "";
>
> // Get the last
> strSQL = "SELECT LastName FROM Ante_Pedigree Where @.AnteNum = ?";
> dCmd = new OleDbCommand(strSQL, dbConn);
> dCmd.Parameters.AddWithValue("@.AnteNum", OleDbType.Char).Value = fileid;
> LabelFileNum.Text = LabelFileNum.Text + " " +
> dCmd.ExecuteScalar().ToString();
>
> I get the error "No value given for one or more required parameters."
> Any suggestions ? This similar code worked in asp.net 1.1
> Thanks,
> Jim
>
"SELECT LastName FROM Ante_Pedigree Where @.AnteNum = ?"
There you are comparing @.AnteNum with ? (both seem to be parameters).
Because the ? is already a parameter then the right way should be:
"SELECT LastName FROM Ante_Pedigree Where AnteNum = ?"
This is how it would be with an SQLCommand:
"SELECT LastName FROM Ante_Pedigree Where AnteNum = @.AnteNum"
Hope this helps.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment