473,748 Members | 11,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

One query updates, the other doesn't

dbrewerton
115 New Member
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
4 1215
tlhintoq
3,525 Recognized Expert Specialist
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 New Member
I was overloading wizard finish by trying to execute all three queries.
Nov 30 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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 New Member
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
1208
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 table 2 ======== ========
0
5678
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 i am in mysql, and i type any comand, like show databases, i get
1
1407
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 message."; myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2; myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost";...
18
2161
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 has a <theadand a <tbody>. In the first example, the <theadstays fixed at the top of the div as it scrolls. In the second example the <theadscrolls away. Could anyone tell me what about the second page makes it not work? Thanks Luminari
6
1499
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. thnx..
1
1433
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 they move from room to room in a hospital setting. I have a table for patient demographics, called “Patients”, one for room numbers and information, called “Rooms”, and one for information on movements from room to room, called “Movement.”...
3
1972
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 results at all in an otherwise functioning C# web application program: SELECT * FROM RR_Contacts WHERE FirstName LIKE '*Robert*' While this query works (gives a result set) with either single or double quotes etc etc using Access to execute the...
1
1987
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 total-report I'd like to add the possibility to compare current numbers and numbers from previous dates. So my idea was calculate the total each time I press the "Create report"-button and then copy these numbers into a table (a table which also keeps...
1
1456
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 number would be generated automatically when the largest one on this table has records against it in another table. This would allow the user to save all documents for one trade against the currentyear#### code and allow quick searching. Im...
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.