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. Desparate ASP.NET newbie needs help with simple questions. HELP!!!

Desparate ASP.NET newbie needs help with simple questions. HELP!!!

Scheduled Pinned Locked Moved ASP.NET
helpdatabasecsharphtmlasp-net
3 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.
  • I Offline
    I Offline
    Infernojericho
    wrote on last edited by
    #1

    Sorry to be a pain in the ass, I am not completely familiar ASP.NET, and I have a huge project (well...it seems HUGE to me...) And I am stuck on a some questions which I think should be very easy for you guys. 1. What I am trying to do right now is let user add new records, the records will be written into an Access 2003 database. right after the record is written I want the primary key of the record to be displayed. The following is the code: OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string strSQL; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"xxx.mdb ;"; strSQL = "SELECT orderID FROM orders WHERE orderdate = '" + CurrentDate + "'AND ordertime='" + CurrentTime + "'AND screenname='" + ScreenName + "'"; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); string OrderID = (string)objCommand.ExecuteScalar(); objConnection.Close(); I am sure the database connection settings are correct, since I was able to use the same settings for other database operations on my site. However, everytime I try to execute the code above, I get an error message saying that string OrderID = (string)objCommand.ExecuteScalar(); has a type mismatch. The field orderID is a automatic field that is the primary key. It is a long integer. I tried int OrderID = (int)objCommand.ExecuteScalar(), double OrderID = (double)objCommand.ExecuteScalar(), but I have the same error message. I believe the SQL statement should be correct, what else could I be missing??? 2. how do you manage to "hold" the website for a specified number of seconds before redirecting it to somewhere else? I know Response.Redirect("xxx.html") is used to redirect the site, but how do you hold it for a couple of seconds? 3. I am trying to use Automatic Paging with datagrid, here is what I did, I have set the AllowCustomPaging to FALSE, and AllowPaging to TRUE. I have OnPageIndexChanged="PageChanger" in the DataGrid tags. In PageChanger, it is simply the connection to the DataGrid, which is: OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @

    C 1 Reply Last reply
    0
    • I Infernojericho

      Sorry to be a pain in the ass, I am not completely familiar ASP.NET, and I have a huge project (well...it seems HUGE to me...) And I am stuck on a some questions which I think should be very easy for you guys. 1. What I am trying to do right now is let user add new records, the records will be written into an Access 2003 database. right after the record is written I want the primary key of the record to be displayed. The following is the code: OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string strSQL; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"xxx.mdb ;"; strSQL = "SELECT orderID FROM orders WHERE orderdate = '" + CurrentDate + "'AND ordertime='" + CurrentTime + "'AND screenname='" + ScreenName + "'"; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); string OrderID = (string)objCommand.ExecuteScalar(); objConnection.Close(); I am sure the database connection settings are correct, since I was able to use the same settings for other database operations on my site. However, everytime I try to execute the code above, I get an error message saying that string OrderID = (string)objCommand.ExecuteScalar(); has a type mismatch. The field orderID is a automatic field that is the primary key. It is a long integer. I tried int OrderID = (int)objCommand.ExecuteScalar(), double OrderID = (double)objCommand.ExecuteScalar(), but I have the same error message. I believe the SQL statement should be correct, what else could I be missing??? 2. how do you manage to "hold" the website for a specified number of seconds before redirecting it to somewhere else? I know Response.Redirect("xxx.html") is used to redirect the site, but how do you hold it for a couple of seconds? 3. I am trying to use Automatic Paging with datagrid, here is what I did, I have set the AllowCustomPaging to FALSE, and AllowPaging to TRUE. I have OnPageIndexChanged="PageChanger" in the DataGrid tags. In PageChanger, it is simply the connection to the DataGrid, which is: OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Infernojericho wrote:

      I am sure the database connection settings are correct, since I was able to use the same settings for other database operations on my site. However, everytime I try to execute the code above, I get an error message saying that string OrderID = (string)objCommand.ExecuteScalar(); has a type mismatch. The field orderID is a automatic field that is the primary key. It is a long integer. I tried int OrderID = (int)objCommand.ExecuteScalar(), double OrderID = (double)objCommand.ExecuteScalar(), but I have the same error message. I believe the SQL statement should be correct, what else could I be missing???

      The value of the first column of the first row of the SELECT is either not a string, or there is no value. From the code you supplied it is possible that the the statement returns no rows, in which case the return from ExecuteScalar() will be null. Also, you may wish to look into this article on SQL Injection attacks and tips on how to prevent them[^] as your code could quite easily be attacked. 2.

      Infernojericho wrote:

      how do you manage to "hold" the website for a specified number of seconds before redirecting it to somewhere else? I know Response.Redirect("xxx.html") is used to redirect the site, but how do you hold it for a couple of seconds?

      I'm not exactly sure what you mean. Why would you want to delay the redirect? You could always put in a Thread.Sleep(milliseconds) somewhere in your code to pause it for a certain amount of time, however, it wouldn't exactly enhance the user experience. 3. No idea. 4.

      Infernojericho wrote:

      4. How do you "check/uncheck" a Checkbox under a certain condition, I tried if (condition matches to a certain criteria) { CheckBoxName.Checked==true; }

      You have a double equals sign rather than a single equals sign. = means assignment. == means a logical comparison.

      Infernojericho wrote:

      5. Is it possible to use a different color for an entire row in a Datagrid if it matches a certain criteria? (Not the Item and AlternatingItem Colors

      I 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Infernojericho wrote:

        I am sure the database connection settings are correct, since I was able to use the same settings for other database operations on my site. However, everytime I try to execute the code above, I get an error message saying that string OrderID = (string)objCommand.ExecuteScalar(); has a type mismatch. The field orderID is a automatic field that is the primary key. It is a long integer. I tried int OrderID = (int)objCommand.ExecuteScalar(), double OrderID = (double)objCommand.ExecuteScalar(), but I have the same error message. I believe the SQL statement should be correct, what else could I be missing???

        The value of the first column of the first row of the SELECT is either not a string, or there is no value. From the code you supplied it is possible that the the statement returns no rows, in which case the return from ExecuteScalar() will be null. Also, you may wish to look into this article on SQL Injection attacks and tips on how to prevent them[^] as your code could quite easily be attacked. 2.

        Infernojericho wrote:

        how do you manage to "hold" the website for a specified number of seconds before redirecting it to somewhere else? I know Response.Redirect("xxx.html") is used to redirect the site, but how do you hold it for a couple of seconds?

        I'm not exactly sure what you mean. Why would you want to delay the redirect? You could always put in a Thread.Sleep(milliseconds) somewhere in your code to pause it for a certain amount of time, however, it wouldn't exactly enhance the user experience. 3. No idea. 4.

        Infernojericho wrote:

        4. How do you "check/uncheck" a Checkbox under a certain condition, I tried if (condition matches to a certain criteria) { CheckBoxName.Checked==true; }

        You have a double equals sign rather than a single equals sign. = means assignment. == means a logical comparison.

        Infernojericho wrote:

        5. Is it possible to use a different color for an entire row in a Datagrid if it matches a certain criteria? (Not the Item and AlternatingItem Colors

        I Offline
        I Offline
        Infernojericho
        wrote on last edited by
        #3

        Thanks for the swift reply and the tip, Colin!!! That was very useful. Unfortunately some of it didn't quite work. I wanted to create something like a splash screen, where it waits for a few seconds, then have it automatically redirect to another URL. So there is no built in functions in ASP.NET that supports this function? As for the checkbox, my bad. I made the operator change from == to =. There is no error message now, however, I see nothing happening at all; the checkbox is not checked when the condition is met I've heard something called a Postback, could this be the culprit? For the 1st question, what would you recommend for extracting the primary key value right after a record has been written? It is very important for me because it is the core sections of my site. Is there other functions in SQL that actually allows you to such operations? By the way, another small question, in my Access database, I have 2 fields, one is date, and another is time, both in datetime format. What I extract them as string and display it in a textbox, The date becomes " 27/12/2005 0:00:00 " and the time becomes "30/12/1899 0:17:31," which means I am always getting both time and date, is there a function that allows me to only retrieve one of them? Thanks again for any help on this matter!!! Jericho

        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