Update to SQL Server is NOT Working

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Update to SQL Server is NOT Working

    I am using the following code in response to a button press.
    SqlConnection sqlConn;
    SqlCommand sqlCmd;

    sqlUpdate = "update ACCGreatest set Votes = (select Votes
    + 1 from ACCGreatest where PlayerID = " +
    Convert.ToInt32(ddlGreatest.SelectedItem.Value.ToS tring()) + ") where
    PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
    sqlConn = new
    SqlConnection("server=(local);uid=accfb;password=a ccrules;database=ACCFB");
    sqlCmd = new SqlCommand(sqlUpdate, sqlConn);
    sqlConn.Open();
    try
    {
    sqlCmd.ExecuteNonQuery();
    }
    catch(SqlException ae)
    {
    Response.Write("SQL Exception: " + ae.ToString());
    }
    sqlConn.Close();

    Unfortunately, it is not working. Can anyone see why this would be
    happening? I can take the update string and use it in the SQL Analyzer
    and it works fine. So what gives?

    TIA,
    Mike
    someone Guest

  2. Similar Questions and Discussions

    1. CFHTTP not working after 7.0.1 Update
      Our current config: Win2K, CFMX7 Standard and have applied the 7.0.1 update. It appears the CFHTTP tag is hanging and we are receiving a HTTP 500 -...
    2. PHP Update query not working
      Hello, I'm using a standard update query and getting an error message. Here is the code: if ((isset($HTTP_POST_VARS)) && ($HTTP_POST_VARS ==...
    3. Update record not working
      Hi, I have developed a cms with php,mysql, apache and have done this on my apache testing server. I uploaded the database to the live server,...
    4. Update not working :(
      Hi, I cant seem to find the problem, I hav an update for which displays items to choose from and then a form at the bottom to enter the model id...
    5. Template update not working...
      Hi! I've been maintaining my site using a previous version of Dreamweaver on an old PC. I've now installed MX on a new PC, and have downloaded the...
  3. #2

    Default Re: Update to SQL Server is NOT Working

    What is the exception you are getting? What is the line number that causes
    the issue?

    Also, why are you converting a string to an intenger? You are concatenating
    strings - so leave it as a string. This may be the cause of your problem.

    "someone" <someone@somewhere.com> wrote in message
    news:ccljgv4ug9kc3iaab88p45ke0st83r59jj@4ax.com...
    > I am using the following code in response to a button press.
    > SqlConnection sqlConn;
    > SqlCommand sqlCmd;
    >
    > sqlUpdate = "update ACCGreatest set Votes = (select Votes
    > + 1 from ACCGreatest where PlayerID = " +
    > Convert.ToInt32(ddlGreatest.SelectedItem.Value.ToS tring()) + ") where
    > PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
    > sqlConn = new
    >
    SqlConnection("server=(local);uid=accfb;password=a ccrules;database=ACCFB");
    > sqlCmd = new SqlCommand(sqlUpdate, sqlConn);
    > sqlConn.Open();
    > try
    > {
    > sqlCmd.ExecuteNonQuery();
    > }
    > catch(SqlException ae)
    > {
    > Response.Write("SQL Exception: " + ae.ToString());
    > }
    > sqlConn.Close();
    >
    > Unfortunately, it is not working. Can anyone see why this would be
    > happening? I can take the update string and use it in the SQL Analyzer
    > and it works fine. So what gives?
    >
    > TIA,
    > Mike

    Marina Guest

  4. #3

    Default Re: Update to SQL Server is NOT Working

    The data type in the database is int so I assumed that I needed to
    convert it to the appropriate data type.
    The weird thing is that it is not throwing an error but still not
    performing the update. Does my approach seem reasonable to you?
    - Create a connection
    - Create a sql command based on the connection
    - Open the connection
    - Execute a non query
    - Close the connection
    All seems pretty straight forward to me. I have a datagrid that has
    been easier to work with than this!! ARGH

    Mike

    On Mon, 7 Jul 2003 16:38:57 -0400, "Marina"
    <zlatkinam@nospam.hotmail.com> wrote:
    >What is the exception you are getting? What is the line number that causes
    >the issue?
    >
    >Also, why are you converting a string to an intenger? You are concatenating
    >strings - so leave it as a string. This may be the cause of your problem.
    >
    >"someone" <someone@somewhere.com> wrote in message
    >news:ccljgv4ug9kc3iaab88p45ke0st83r59jj@4ax.com.. .
    >> I am using the following code in response to a button press.
    >> SqlConnection sqlConn;
    >> SqlCommand sqlCmd;
    >>
    >> sqlUpdate = "update ACCGreatest set Votes = (select Votes
    >> + 1 from ACCGreatest where PlayerID = " +
    >> Convert.ToInt32(ddlGreatest.SelectedItem.Value.ToS tring()) + ") where
    >> PlayerID = " + Convert.ToInt32(ddlGreatest.SelectedItem.Value);
    >> sqlConn = new
    >>
    >SqlConnection("server=(local);uid=accfb;password= accrules;database=ACCFB");
    >> sqlCmd = new SqlCommand(sqlUpdate, sqlConn);
    >> sqlConn.Open();
    >> try
    >> {
    >> sqlCmd.ExecuteNonQuery();
    >> }
    >> catch(SqlException ae)
    >> {
    >> Response.Write("SQL Exception: " + ae.ToString());
    >> }
    >> sqlConn.Close();
    >>
    >> Unfortunately, it is not working. Can anyone see why this would be
    >> happening? I can take the update string and use it in the SQL Analyzer
    >> and it works fine. So what gives?
    >>
    >> TIA,
    >> Mike
    >
    someone Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139