Databases :: MySql Transaction Inside A Loop - Delete A Bunch Of Records

Sep 30, 2010

I'm trying to delete a bunch of records in mysql. The record info to delete (userid, name) is stored in an arraylist. It seems to only delete the first record and gives an error ("Transaction has already been rolled back or is not pending.") afterwards. I have the transaction commit inside the loop which I think is the issue but not sure how to go further if I bring it outside of the loop. Here's the relevant bits of the code.

try
{
ArrayList alist = new ArrayList();
//alist gets populated with data like (12345,robot)(23456,car) here.
MySqlConnection conn2 = new MySqlConnection(query_connection);
conn2.Open();
MySqlCommand command2 = conn2.CreateCommand();
MySqlTransaction mytransaction;
mytransaction = conn2.BeginTransaction();
command2.Transaction = mytransaction;
for (int i = 0; i < alist.Count; i++)
{
string[] s = alist[i].ToString().Split(',');
try
{
command2.CommandText = "DELETE from users_settings WHERE UserID=" + s[0].ToString();
command2.ExecuteNonQuery();
command2.CommandText = "DELETE from users WHERE ID=" + s[0].ToString();
command2.ExecuteNonQuery();
mytransaction.Commit();
}
catch (Exception e){
mytransaction.Rollback();
}
}
}
catch(Exception e){
}

View 1 Replies


Similar Messages:

Databases :: Delete Duplicate Records From MySQL Table?

Sep 20, 2010

I have Revision column in Quote table with time stamp (MySql table) now i am viewing the entire date and time my end user want to view only Date he doesnot want to see time how can i pull only date.i am displaying revision column in two ways one in grid view and another one in field value

Query in my Grid view

Dim query As String = "SELECT QuoteNumber,Revision,Vendor,PartNumber,status,Customer,Requestor from quotes"

On select check box in grid view, filed values will be loaded with data.

field value

txtRev.Text = dt.Rows(indx)("Revision").ToString()

View 3 Replies

Databases :: Transaction In Mysql For Update For Each Row Of Gridview

Feb 2, 2011

i am having a transaction related problem regarding mysql.. need some advice how to proceed !!!

here is a gridview for my application and i am inserting or updating for each row.... like

[Code]....

well now what i want is if any of the row update or insert failes ... it should revert all the changes that was already made into the database ... even a single row update .. into that perticular table ... the code which i have called for payment.Update(PayDetails, 0) is :

[Code]....

can someone help me out how to proceed in this scenario ??? how do i undo each of the updates made into the table payment schedule details ...

View 1 Replies

Databases :: Delete The Row From Mysql?

Mar 25, 2011

i have populated the gridview dynamically and set the ShowDeleteButton = true.. i have the delete command but i cant delete the specific row i wanted to delete..

here is my gridview code:

<asp:GridView ID="GridView1" runat="server" ShowDeleteButton="true" Width="540px"
AutoGenerateDeleteButton="True" GridLines="None">

and here is the code behind:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string ann = (GridView1.DataKeys[e.RowIndex].Values[3].ToString());
MySqlCommand update = new MySqlCommand("DELETE FROM announcement where ID = '"+ann+"'", conn);

[Code]....

how to get the values of the row that i want to delete.

View 2 Replies

Databases ::asp.net 2010 And Mysql Are Practical For 10 Million Records ?

Aug 12, 2010

I am developing a large e-commerce system.

I am using asp.net 2010 with mysql database. Is it practical for large amounts of data ? say 10 million records ? cuz some people said to me that using this combination, i'll be having performance issues as database grows.

View 4 Replies

Databases :: MySQL And Auto Generating Insert,Update - Delete Statements?

May 11, 2010

Before I get too far down the road I just want some advice. I'm building a web app using VWD2008 and MySQL 5. I've got the membership provider stuff working fine and have an odbc connection setup which works "fine". what I've noticed is that when I configure a new sqldatasource (that will be used to provide data to a listview or something) the Advanced -> generate Insert,Update..... option is disabled. I'm assuming its because of the sql syntax difference of the square brackets issue between MS SQL Server and MySQL.

Before I start writing all my own insert and update statements does anyone know if there is a way to get MySQL and VWD to talk the same language, maybe a different connector or something. I'm using mysql-connector-odbc-3.51.15

View 7 Replies

Databases :: Using Mysql Installed Mysql And Mysql Net Connector?

Dec 26, 2010

i was just using mysql i installed mysql and mysql net connector. its installed successfully but unable tp add to references.

View 3 Replies

SQL Server :: Updating Bunch Of Records At Time?

Sep 15, 2010

If I want to update 1000 records at a time in the database what is the best approach.

View 6 Replies

Mono + Mysql = Slow - Inserts 26,000 Records Into A Mysql Database

Dec 16, 2010

Why does a very simple script which inserts 26,000 records into a mysql database (myisam, no transactions) take 13 seconds in the php implementation, and then 35-50 seconds using mono+mysql connector? I thought asp.net was faster than php? Could the problem be the mono mysql connector is "platform independent", so the performance just stinks? or does asp.net suffer more overhead than php when it comes to executing each query? Aren't there any native linux binaries for mysql connector for mono that may be faster?

View 1 Replies

VS 2008 - Send A Bunch Of Looped Records From Database To JavaScript Array

Mar 21, 2012

I'm trying to send a bunch of looped records from database to javascript array in codebehind to add overlays to the googlemap markers. So farthe code below only provide me the first marker.

PHP Code:

private void BuildScript(DataTable tbl)
    {
        String Markers = "";
        foreach (DataRow r in tbl.Rows)
        {
        
[code]...

View 1 Replies

Databases :: MYSQL Using VB With VWD2008 For MYSQL Data Transactions

Jan 11, 2010

I have used ASD.NET code using SQL Database for Transaction operation successfully. By changing the Database Code to interface with MYSQL an Error occurs. If I remove the Transaction Code from within the the application, it works OK by displaying the MYSQL data (Read Only) in the layout of the application. I am using Mysql Essential-4.1.22-win32 and MYSQL Connector ODBC-3.51.2. My objective is to EDIT the MYSQL Data.

View 8 Replies

Forms Data Controls :: How To Insert The Records Based On The 1st Sp Ouput Should Be For Loop Which Many Records

Nov 10, 2010

[Code]....

this is my html code

[Code]....

this is my code behind

[Code]....

this is my bal code

acuttally

in my javascript popup i am getting the checked values but i need it in record by record in the lblsave data

View 2 Replies

SQL Server :: Adding A Bunch Of New Records To The English Table / Repeating The Data Entry Into The Spanish Table

Oct 29, 2010

I have two tables for storing language translations - tblEN and tblES. They have the same structure which is nvcEnglish and nvcLocal - both nVarChar fields.

In nvcLocal of the Spanish table, I enter the Spanish translations of words and phrases used within my app. Problem is, when I add a bunch of new records to the English table I also have to go in and repeat the data entry into the Spanish table. I am wondering if there is a way to import the newly added records into the Spanish table using Transact SQL?The plain language query would be something like:

If the data in tblEN.nvcEnglish does not exist in tblES.nvcEnglish then insert a new row into tblES with the values from tblEN

View 5 Replies

Web Forms :: Delete File And Update Database In Transaction?

Feb 20, 2010

I want to delete file available on server and same time I want to update the filename column in my database.If I delete file first and then update database and an error come in updating database my file is already gone.If I update database first and then delete file from from disk and an error occur my file information in database is already gone Can any one tell me how I can do it both successfully. I means either both operations should succeed or I should not lose my physical file or its information in database.

View 3 Replies

Loop Through All Records

Dec 10, 2010

I am getting out parameter of type DbType.Xml in .net code. What is the better way to loop through all the records and do some operation.

View 1 Replies

How To Loop Through All Records

May 11, 2010

I need to loop through all my db records, append some text a specific column (for all records), and save back to the db.

View 3 Replies

C# - Creating Strings Inside A For Each Loop? Or Creat Them Outside, Use Inside?

Dec 10, 2010

i have the following code below and was lookign to clean it up, but am not sure if it needs clean up or not.

foreach (SearchResult sr in mySrchColl)
{
string strValIn = sr.Properties["in"][0].ToString();
string strValOut= sr.Properties["out"][0].ToString();
}

do i change this to something like this:

string strValIn = "";
string strValOut= "";
foreach (SearchResult sr in mySrchColl)

[code]...

whats the difference or are these two identical?

View 6 Replies

Databases :: How To Connect To MySQL

Jan 18, 2010

I am also having the same problem while establishing a connection in mysql and asp.net..So how do i solve it...

View 5 Replies

Databases :: MySQL Connector With 64 Bit?

May 3, 2010

I just moved to a new 2008 64 Bit Server. We are using MySQL, now also the 64 Bit version. Now I found out that there is a 64 Bit ODCB Driver, but not an 64 Bit Net/Connector.

Is that an issue or is the .NET Connector by default 32 and 64 Bit?

View 5 Replies

Databases :: What Is The Alternative Of CTS In MySQL

Mar 1, 2011

Can anybody tell me what is the alternative of CTS(Common table expression in SQL Server 2005) in MySQL

View 1 Replies

Databases :: Use MVC 2 With MySQL Database?

Jun 15, 2010

I want to use MVC 2 with MySQL database. Is it possible?because my shared hosting limits the size of SQL Server database, but there is no limit on Size of MySQL database.MySQL seems to take less disk space than SQL Server database which is costly on the Internet.

View 1 Replies

Databases :: Connection To MySQL Database

May 15, 2010

I did all the instructions which are in the following link: [URL] in order to do a connection between MySQL database and ASP.NET but I did not successed. Sometimes, it told me that I have a mistake in the <asp: button> and sometimes it told me that I did a mistake in calling (addImage) method. And this is my whole code:-

&#65279;<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HW5._Default" %>
<script>
public class DataAccess
{
private string _strConn =
@"Driver= {MySQLODBC 3.51 Driver};SERVER=localhost;DATABASE=test1;";
private OdbcConnection _objConn;
public DataAccess()
{
this._objConn = new OdbcConnection(this._strConn);
}
// This function adds the Images to database
public string addImage(timestamp id, byte [] data,string extension)
{
string strSql = "SELECT * FROM File";
DataSet ds = new DataSet("Image");
OdbcDataAdapter tempAP = new OdbcDataAdapter(strSql,this._objConn);
OdbcCommandBuilder objCommand = new OdbcCommandBuilder(tempAP);
tempAP.Fill(ds,"Table");
try
{
this._objConn.Open();
DataRow objNewRow = ds.Tables["Table"].NewRow();
objNewRow["Extension"] = extension;
objNewRow["Data"] = buffer;
objNewRow["ID"] = id;
ds.Tables["Table"].Rows.Add(objNewRow);
// trying to update the table to add the image
tempAP.Update(ds,"Table");
}.....................................

View 4 Replies

Databases :: How To Connect Mysql Database

Jun 11, 2010

how to connect mysql database in asp.net?

I am install mysql 5.0 then i install sqlyog.

After that i create the database sample in mysql with the help of sqlyog.

I want to connect the database in asp.net & display it on gridview.

[Code]....

How we set the connection string in mysql for use on aspx page?

View 1 Replies

Databases :: Auto Complete Using MySQL?

Mar 14, 2010

I'm trying to apply this example to my website.They use SQLServer in this link[URL]string sql = "Select * from Country Where Country_Name like @prefixText";i have to change the last part( like @prefix ) so that it wont give any errors for MySQL

View 12 Replies

Databases :: Import Xls Data To MySQL?

Apr 15, 2010

Is there any way to import XLS data into MySQL database which is have similar table structure..?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved