![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? > 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||