473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

One query updates, the other doesn't

dbrewerton
115 100+
Ok, I'm using code-behind with a MySQL DB to update two tables. It updates the addressbook table fine but the device table won't update. I know its probably some stupid syntax error but I am not seeing it. To be sure I have the right variables set, I am using labels for the IDs. The ID numbers are correct. Can someone help? Thanks.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Web.UI.HtmlControls;
  8. using System.Data.OleDb;
  9. using System.Data.Odbc;
  10.  
  11. public partial class editassign : System.Web.UI.Page
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.         Session["aspnet"] = Request.QueryString[0];
  16.  
  17.         int counting = GridView1.Rows.Count;
  18.         if (counting == 0)
  19.         {
  20.             GridView1.Visible = false;
  21.             Wizard1.Visible = true;
  22.         }
  23.         else
  24.         {
  25.             GridView1.Visible = true;
  26.             Wizard1.Visible = false;
  27.         }
  28.     }
  29.  
  30.     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  31.     {
  32.         Session["contact_id"] = this.DropDownList1.SelectedItem.Value;
  33.     }
  34.  
  35.     protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
  36.     {
  37.         Session["device_id"] = this.DropDownList2.SelectedItem.Value;
  38.         Label1.Text = Convert.ToString(Session["aspnet"]);
  39.         Label2.Text = Convert.ToString(Session["contact_id"]);
  40.         Label3.Text = Convert.ToString(Session["device_id"]);
  41.     }
  42.  
  43.     protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
  44.     {
  45.         OdbcConnection con = null;
  46.         OdbcCommand cmd = null;
  47.  
  48.         try
  49.         {
  50.             con = new OdbcConnection();
  51.             con.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};server=MyDBServer;database=MyDB;uid=MyUser;pwd=MyPass;";
  52.             cmd = new OdbcCommand();
  53.             cmd.Connection = con;
  54.             cmd.Parameters.Add("?aspnet_id", OdbcType.Int).Value = (Session["aspnet"] != null) ? Convert.ToInt32(Session["aspnet"]) : 1;
  55.             cmd.Parameters.Add("?contact_id", OdbcType.Int).Value = (Session["contact_id"] != null) ? Convert.ToInt32(Session["contact_id"]) : 0;
  56.             con.Open();
  57.             // This one works fine
  58.             cmd.CommandText = "update egw_addressbook set aspnet_id = ? where contact_id = ?;";
  59.             cmd.ExecuteNonQuery();
  60.  
  61.             // These two don't. Even tried combining, no better.
  62.             cmd.Parameters.Add("?aspnet_id", OdbcType.Int).Value = (Session["aspnet"] != null) ? Convert.ToInt32(Session["aspnet"]) : 1;
  63.             cmd.Parameters.Add("?device_id", OdbcType.Int).Value = (Session["device_id"] != null) ? Convert.ToInt32(Session["device_id"]) : 0;
  64.             cmd.CommandText = "update ewise_device set aspnet_id = ? where device_id = ?;";
  65.             cmd.ExecuteNonQuery();
  66.  
  67.             cmd.Parameters.Add("?contact_id", OdbcType.Int).Value = (Session["contact_id"] != null) ? Convert.ToInt32(Session["contact_id"]) : 1;
  68.             cmd.Parameters.Add("?device_id", OdbcType.Int).Value = (Session["device_id"] != null) ? Convert.ToInt32(Session["device_id"]) : 0;
  69.             cmd.CommandText = "update ewise_device set contact_id = ? where device_id = ?;";
  70.             cmd.ExecuteNonQuery();
  71.         }
  72.         catch (Exception)
  73.         {
  74.             throw;
  75.         }
  76.         finally
  77.         {
  78.             con.Close();
  79.         }
  80.     }
  81. }
Nov 30 '09 #1

✓ answered by Frinavale

I'm glad you solved your problem.
Next time it would be helpful if you posted the error messages that you are getting. Sometimes it's easier for the experts here to work with error messages rather than having to comb through code to find the problem.

Cheers!

-Frinny

4 1200
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Nov 30 '09 #2
dbrewerton
115 100+
I was overloading wizard finish by trying to execute all three queries.
Nov 30 '09 #3
Frinavale
9,735 Expert Mod 8TB
I'm glad you solved your problem.
Next time it would be helpful if you posted the error messages that you are getting. Sometimes it's easier for the experts here to work with error messages rather than having to comb through code to find the problem.

Cheers!

-Frinny
Nov 30 '09 #4
dbrewerton
115 100+
Agreed, sometimes that slips my mind LOL
Dec 1 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jack | last post by:
Hi, I'm wondering if someone can help with the following problem. I have 2 tables in an access database from which I would like to create a third table. They look like this: table 1 ...
0
by: info | last post by:
i researched for a while on the net and found that more people have this problem, but could not get an answer. i am very new to MySql. linux - feudora i log into mysql using "root" when...
1
by: Jan Paul van de Berg | last post by:
Code (ASP/Javascript): var myMail=Server.CreateObject("CDO.Message"); myMail.Subject="Subject"; myMail.From="info@domain1.blabla"; myMail.To="johndoe@test.blabla"; myMail.TextBody="This is a...
18
by: Luminari | last post by:
I have two pages. Both of them are supposed to have one table on it with a fixed header. Both pages were tested in IE6. Structurally they are identical. Both have a <divthat wraps a <tablethat...
6
by: rhepsi | last post by:
Hii all, i have 2 queries, query1 and query 2 Query1 is selecting from results of Query2... is it possible??? Can somebody provide with code snippets in VB.NET to call such queries. ...
1
by: jcocomo | last post by:
Hi there. I am quite new to MS-Access and databases in general, so please bear with me if this is a very basic question. I am trying to create a database in Access 2000 that will track patients as...
3
by: Budsy | last post by:
This is a peculiar problem for me. I am finding that the following query works perfectly and gives the expected result set when used in the Access query design environment, but it simply gives no...
1
by: SydBlack | last post by:
Hi I'm creating a simple inventory system with the option to print reports for individual accounts or grand total for all accounts. The individual reports works just fine, but for the grand...
1
by: Phil Gsy | last post by:
Hi i would like to add a new table (TRADE_SEQ) to my document management database which would contain a squential number in the format currentyear#### so it would start at 20100001. The next sequence...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.