Parameter Problem in OleDB

B

Benedictum

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?
 
M

Mr. Arnold

Benedictum said:
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.
 

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

Top