Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Parameter Problem in OleDB

Reply
 
Old 09-29-2008   #1 (permalink)
Benedictum


 
 

Parameter Problem in OleDB

I have the following code that derives the value from a query string -
// the code ->

protected void Page_Load(object sender, EventArgs e)

{

string theTime = Request.QueryString["time"];

string altitude = Request.QueryString["altitude"];

string latitude = Request.QueryString["latitude"];

string longitude = Request.QueryString["longitude"];

lblTtime.Text = theTime;

lblAltitude.Text = altitude;

lblLatitude.Text = latitude;

lblLongitude.Text = longitude;

if (theTime == "" || altitude == "" || latitude == "" || longitude == "")

{

// do nothing

}

else

{

string conn =
ConfigurationManager.AppSettings["ConnectionString"].ToString();

// lblConn.Text = conn;

string selectSQL = "update gps_table set ";

selectSQL += "gps_time= @gps_time,";

selectSQL +="gps_altitude = @gps_altitude,";

selectSQL +="gps_latitude = @gps_latitude,";

selectSQL +="gps_longitude = @gps_longitude where gps_id=1";

OleDbConnection MyConnection = new OleDbConnection(conn);

OleDbCommand MyCommand = new OleDbCommand(selectSQL, MyConnection);

MyCommand.Parameters.Add(new OleDbParameter("@gps_time",
Convert.ToDateTime(theTime)));

MyCommand.Parameters.Add(new OleDbParameter("@gps_altitude",
Convert.ToDouble(altitude)));

MyCommand.Parameters.Add(new OleDbParameter("@gps_latitude", latitude));

MyCommand.Parameters.Add(new OleDbParameter("@gps_longitude", longitude));

MyConnection.Open();

MyCommand.ExecuteNonQuery();

}

I am getting the exception : Parameter @gps_latitude has no default value.



Why? How I can I solve this problem? Is this a VS2005 bug?



My System SpecsSystem Spec
Old 10-05-2008   #2 (permalink)
Mr. Arnold


 
 

Re: Parameter Problem in OleDB


"Benedictum" <Benedictus@xxxxxx> wrote in message
news:eluzu3pIJHA.3644@xxxxxx
Quote:

>I have the following code that derives the value from a query string -
> // the code ->
>
> protected void Page_Load(object sender, EventArgs e)
>
> {
>
> string theTime = Request.QueryString["time"];
>
> string altitude = Request.QueryString["altitude"];
>
> string latitude = Request.QueryString["latitude"];
>
> string longitude = Request.QueryString["longitude"];
>
> lblTtime.Text = theTime;
>
> lblAltitude.Text = altitude;
>
> lblLatitude.Text = latitude;
>
> lblLongitude.Text = longitude;
>
> if (theTime == "" || altitude == "" || latitude == "" || longitude == "")
>
> {
>
> // do nothing
>
> }
>
> else
>
> {
>
> string conn =
> ConfigurationManager.AppSettings["ConnectionString"].ToString();
>
> // lblConn.Text = conn;
>
> string selectSQL = "update gps_table set ";
>
> selectSQL += "gps_time= @gps_time,";
>
> selectSQL +="gps_altitude = @gps_altitude,";
>
> selectSQL +="gps_latitude = @gps_latitude,";
>
> selectSQL +="gps_longitude = @gps_longitude where gps_id=1";
>
> OleDbConnection MyConnection = new OleDbConnection(conn);
>
> OleDbCommand MyCommand = new OleDbCommand(selectSQL, MyConnection);
>
> MyCommand.Parameters.Add(new OleDbParameter("@gps_time",
> Convert.ToDateTime(theTime)));
>
> MyCommand.Parameters.Add(new OleDbParameter("@gps_altitude",
> Convert.ToDouble(altitude)));
>
> MyCommand.Parameters.Add(new OleDbParameter("@gps_latitude", latitude));
>
> MyCommand.Parameters.Add(new OleDbParameter("@gps_longitude", longitude));
>
> MyConnection.Open();
>
> MyCommand.ExecuteNonQuery();
>
> }
>
> I am getting the exception : Parameter @gps_latitude has no default value.
>
>
>
> Why? How I can I solve this problem? Is this a VS2005 bug?
>
No, it's not a bug. I don't use OleDb. I use SQL Command Objects myself,
which would be using a T-SQL Update statement. However, it must be that
ADO.Net and Oledb are looking at the Parm.Add for "@gps_latitude", latitude
and latitude is null or something and maybe another "," needs to be in the
statement to indicate what default value should be given if latitude is null
data.

You can approach it at that angle. You should find out what is in latitude
and find out how to give a default value if Oledb determines that it needs a
default value applied to make the statement successful.


My System SpecsSystem Spec
Old 10-05-2008   #3 (permalink)
Jack Jackson


 
 

Re: Parameter Problem in OleDB

OLEDb uses positional parameters marked by ?, not @.

See
<http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.aspx>


On Mon, 29 Sep 2008 20:43:24 -0500, "Benedictum"
<Benedictus@xxxxxx> wrote:
Quote:

>I have the following code that derives the value from a query string -
>// the code ->
>
>protected void Page_Load(object sender, EventArgs e)
>
>{
>
>string theTime = Request.QueryString["time"];
>
>string altitude = Request.QueryString["altitude"];
>
>string latitude = Request.QueryString["latitude"];
>
>string longitude = Request.QueryString["longitude"];
>
>lblTtime.Text = theTime;
>
>lblAltitude.Text = altitude;
>
>lblLatitude.Text = latitude;
>
>lblLongitude.Text = longitude;
>
>if (theTime == "" || altitude == "" || latitude == "" || longitude == "")
>
>{
>
>// do nothing
>
>}
>
>else
>
>{
>
>string conn =
>ConfigurationManager.AppSettings["ConnectionString"].ToString();
>
>// lblConn.Text = conn;
>
>string selectSQL = "update gps_table set ";
>
>selectSQL += "gps_time= @gps_time,";
>
>selectSQL +="gps_altitude = @gps_altitude,";
>
>selectSQL +="gps_latitude = @gps_latitude,";
>
>selectSQL +="gps_longitude = @gps_longitude where gps_id=1";
>
>OleDbConnection MyConnection = new OleDbConnection(conn);
>
>OleDbCommand MyCommand = new OleDbCommand(selectSQL, MyConnection);
>
>MyCommand.Parameters.Add(new OleDbParameter("@gps_time",
>Convert.ToDateTime(theTime)));
>
>MyCommand.Parameters.Add(new OleDbParameter("@gps_altitude",
>Convert.ToDouble(altitude)));
>
>MyCommand.Parameters.Add(new OleDbParameter("@gps_latitude", latitude));
>
>MyCommand.Parameters.Add(new OleDbParameter("@gps_longitude", longitude));
>
>MyConnection.Open();
>
>MyCommand.ExecuteNonQuery();
>
>}
>
>I am getting the exception : Parameter @gps_latitude has no default value.
>
>
>
>Why? How I can I solve this problem? Is this a VS2005 bug?
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Null parameter problem .NET General
Script parameter problem PowerShell
Using multiple Parameter sets for a Parameter PowerShell
How to best control parameter attributes and parameter parsing in your own scripts? PowerShell
Problem with parameter passing? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46