Parameter Problem in OleDB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Benedictum

    Parameter Problem in OleDB

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

    protected void Page_Load(objec t sender, EventArgs e)

    {

    string theTime = Request.QuerySt ring["time"];

    string altitude = Request.QuerySt ring["altitude"];

    string latitude = Request.QuerySt ring["latitude"];

    string longitude = Request.QuerySt ring["longitude"];

    lblTtime.Text = theTime;

    lblAltitude.Tex t = altitude;

    lblLatitude.Tex t = latitude;

    lblLongitude.Te xt = longitude;

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

    {

    // do nothing

    }

    else

    {

    string conn =
    ConfigurationMa nager.AppSettin gs["ConnectionStri ng"].ToString();

    // lblConn.Text = conn;

    string selectSQL = "update gps_table set ";

    selectSQL += "gps_time= @gps_time,";

    selectSQL +="gps_altitu de = @gps_altitude," ;

    selectSQL +="gps_latitu de = @gps_latitude," ;

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

    OleDbConnection MyConnection = new OleDbConnection (conn);

    OleDbCommand MyCommand = new OleDbCommand(se lectSQL, MyConnection);

    MyCommand.Param eters.Add(new OleDbParameter( "@gps_time" ,
    Convert.ToDateT ime(theTime)));

    MyCommand.Param eters.Add(new OleDbParameter( "@gps_altitude" ,
    Convert.ToDoubl e(altitude)));

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

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

    MyConnection.Op en();

    MyCommand.Execu teNonQuery();

    }

    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?


  • Mr. Arnold

    #2
    Re: Parameter Problem in OleDB


    "Benedictum " <Benedictus@dom inusvobis.comwr ote in message
    news:eluzu3pIJH A.3644@TK2MSFTN GP05.phx.gbl...
    >I have the following code that derives the value from a query string -
    // the code ->
    >
    protected void Page_Load(objec t sender, EventArgs e)
    >
    {
    >
    string theTime = Request.QuerySt ring["time"];
    >
    string altitude = Request.QuerySt ring["altitude"];
    >
    string latitude = Request.QuerySt ring["latitude"];
    >
    string longitude = Request.QuerySt ring["longitude"];
    >
    lblTtime.Text = theTime;
    >
    lblAltitude.Tex t = altitude;
    >
    lblLatitude.Tex t = latitude;
    >
    lblLongitude.Te xt = longitude;
    >
    if (theTime == "" || altitude == "" || latitude == "" || longitude == "")
    >
    {
    >
    // do nothing
    >
    }
    >
    else
    >
    {
    >
    string conn =
    ConfigurationMa nager.AppSettin gs["ConnectionStri ng"].ToString();
    >
    // lblConn.Text = conn;
    >
    string selectSQL = "update gps_table set ";
    >
    selectSQL += "gps_time= @gps_time,";
    >
    selectSQL +="gps_altitu de = @gps_altitude," ;
    >
    selectSQL +="gps_latitu de = @gps_latitude," ;
    >
    selectSQL +="gps_longitud e = @gps_longitude where gps_id=1";
    >
    OleDbConnection MyConnection = new OleDbConnection (conn);
    >
    OleDbCommand MyCommand = new OleDbCommand(se lectSQL, MyConnection);
    >
    MyCommand.Param eters.Add(new OleDbParameter( "@gps_time" ,
    Convert.ToDateT ime(theTime)));
    >
    MyCommand.Param eters.Add(new OleDbParameter( "@gps_altitude" ,
    Convert.ToDoubl e(altitude)));
    >
    MyCommand.Param eters.Add(new OleDbParameter( "@gps_latitude" , latitude));
    >
    MyCommand.Param eters.Add(new OleDbParameter( "@gps_longitude ", longitude));
    >
    MyConnection.Op en();
    >
    MyCommand.Execu teNonQuery();
    >
    }
    >
    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.


    Comment

    • Jack Jackson

      #3
      Re: Parameter Problem in OleDB

      OLEDb uses positional parameters marked by ?, not @.

      See
      <http://msdn.microsoft. com/en-us/library/system.data.ole db.oledbparamet er.aspx>


      On Mon, 29 Sep 2008 20:43:24 -0500, "Benedictum "
      <Benedictus@dom inusvobis.comwr ote:
      >I have the following code that derives the value from a query string -
      >// the code ->
      >
      >protected void Page_Load(objec t sender, EventArgs e)
      >
      >{
      >
      >string theTime = Request.QuerySt ring["time"];
      >
      >string altitude = Request.QuerySt ring["altitude"];
      >
      >string latitude = Request.QuerySt ring["latitude"];
      >
      >string longitude = Request.QuerySt ring["longitude"];
      >
      >lblTtime.Tex t = theTime;
      >
      >lblAltitude.Te xt = altitude;
      >
      >lblLatitude.Te xt = latitude;
      >
      >lblLongitude.T ext = longitude;
      >
      >if (theTime == "" || altitude == "" || latitude == "" || longitude == "")
      >
      >{
      >
      >// do nothing
      >
      >}
      >
      >else
      >
      >{
      >
      >string conn =
      >ConfigurationM anager.AppSetti ngs["ConnectionStri ng"].ToString();
      >
      >// lblConn.Text = conn;
      >
      >string selectSQL = "update gps_table set ";
      >
      >selectSQL += "gps_time= @gps_time,";
      >
      >selectSQL +="gps_altitu de = @gps_altitude," ;
      >
      >selectSQL +="gps_latitu de = @gps_latitude," ;
      >
      >selectSQL +="gps_longitud e = @gps_longitude where gps_id=1";
      >
      >OleDbConnectio n MyConnection = new OleDbConnection (conn);
      >
      >OleDbCommand MyCommand = new OleDbCommand(se lectSQL, MyConnection);
      >
      >MyCommand.Para meters.Add(new OleDbParameter( "@gps_time" ,
      >Convert.ToDate Time(theTime))) ;
      >
      >MyCommand.Para meters.Add(new OleDbParameter( "@gps_altitude" ,
      >Convert.ToDoub le(altitude)));
      >
      >MyCommand.Para meters.Add(new OleDbParameter( "@gps_latitude" , latitude));
      >
      >MyCommand.Para meters.Add(new OleDbParameter( "@gps_longitude ", longitude));
      >
      >MyConnection.O pen();
      >
      >MyCommand.Exec uteNonQuery();
      >
      >}
      >
      >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?
      >

      Comment

      Working...