Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. update database from a querystring data

update database from a querystring data

Scheduled Pinned Locked Moved ASP.NET
helpdatabasetestingbeta-testingjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    highjo
    wrote on last edited by
    #1

    hi guys! briefly, i have an application which use an api for its interaction with another plattform.at this point a need to update my database with data from a call from that api which uses querystring to pass data.Simple and fairky straight foward but couldn't suceeded.and the funniest is it doesn't throw any error. tried for 3 days now to find out where the problem is without any changes.i'm sure it just a little thing but can't see it.i would like to ask for help on this. here is my codes the page call.aspx that the api use as callback to pass the data is. protected void Page_Load(object sender, EventArgs e) { gid = Request["Id"]; numbstatus = Request["status"]; if(apimsgid != null && numbstatus != null) { //misc.logerr("callback data :" + gid + " : " + numbstatus); //this line up was to check if the function receives the parameters gid = gid.Trim(); numbstatus= numbstatus.Trim(); if (gid != "" && numbstatus != "") { DatabaseLayer dlayerobj = new DatabaseLayer(); Response.Write(dlayerobj.UpdateStatusByApiId(gid, numbstatus)); } } } } now the function in the database layer is : public string UpdateStatusByApiId(string theapiid, string thestatusnum) { string status = convertStatus(thestatusnum); //the convertStatus method gives a normal name as ok, or no for diferenttype of numbers from the api.no problem here try { SqlCommand updatecmd = new SqlCommand(); updatecmd.CommandType = CommandType.Text; updatecmd.Connection = con; //the connection con is created in the constructor. updatecmd.CommandText = "update TState set DStatus =@stat where Gid=@apid"; updatecmd.Parameters.Add("@stat", SqlDbType.VarChar, 20).Value = status; updatecmd.Parameters.Add("@apid", SqlDbType.VarChar, 128).Value = theapiid; updatecmd.ExecuteNonQuery(); return theapiid + " : " + status; this also to see if the fucntion receives its param well and it receives it } catch (Exception ex) { misc.logerr(ex.ToString()); return ex.ToString(); } } please let me know cause i'm stacked here and can't move forward without this.. ps:can anyone tell me the best practice testing in debugging.i m

    G 1 Reply Last reply
    0
    • H highjo

      hi guys! briefly, i have an application which use an api for its interaction with another plattform.at this point a need to update my database with data from a call from that api which uses querystring to pass data.Simple and fairky straight foward but couldn't suceeded.and the funniest is it doesn't throw any error. tried for 3 days now to find out where the problem is without any changes.i'm sure it just a little thing but can't see it.i would like to ask for help on this. here is my codes the page call.aspx that the api use as callback to pass the data is. protected void Page_Load(object sender, EventArgs e) { gid = Request["Id"]; numbstatus = Request["status"]; if(apimsgid != null && numbstatus != null) { //misc.logerr("callback data :" + gid + " : " + numbstatus); //this line up was to check if the function receives the parameters gid = gid.Trim(); numbstatus= numbstatus.Trim(); if (gid != "" && numbstatus != "") { DatabaseLayer dlayerobj = new DatabaseLayer(); Response.Write(dlayerobj.UpdateStatusByApiId(gid, numbstatus)); } } } } now the function in the database layer is : public string UpdateStatusByApiId(string theapiid, string thestatusnum) { string status = convertStatus(thestatusnum); //the convertStatus method gives a normal name as ok, or no for diferenttype of numbers from the api.no problem here try { SqlCommand updatecmd = new SqlCommand(); updatecmd.CommandType = CommandType.Text; updatecmd.Connection = con; //the connection con is created in the constructor. updatecmd.CommandText = "update TState set DStatus =@stat where Gid=@apid"; updatecmd.Parameters.Add("@stat", SqlDbType.VarChar, 20).Value = status; updatecmd.Parameters.Add("@apid", SqlDbType.VarChar, 128).Value = theapiid; updatecmd.ExecuteNonQuery(); return theapiid + " : " + status; this also to see if the fucntion receives its param well and it receives it } catch (Exception ex) { misc.logerr(ex.ToString()); return ex.ToString(); } } please let me know cause i'm stacked here and can't move forward without this.. ps:can anyone tell me the best practice testing in debugging.i m

      G Offline
      G Offline
      Gayani Devapriya
      wrote on last edited by
      #2

      Hi, First set a break point where you read the data from the QueryString and see whether it retuns the parsed data. (Note: Just check if the Querystring key you use ie: "Id" and "status" has the same spelling as from where you are parsing from.) Also another hint is just parse these values manually to the Query and see whether its working.. And when adding the values to the parameter you could simply use updatecmd.Parameters.AddWithValue("@apid, theapiid); Just some additional infor... And assigned the value you retrive from ExecuteNonQuery to int variable and check if its greater than 0 before going for the next line... And others seems to be fine... Hope it helps.. Thx, Gayani

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups