Click here to Skip to main content
15,887,304 members
Home / Discussions / C#
   

C#

 
GeneralRe: XmlSerializer doesn't serialize Guid? Pin
mav.northwind17-Feb-10 0:16
mav.northwind17-Feb-10 0:16 
AnswerSolution Pin
mav.northwind17-Feb-10 2:11
mav.northwind17-Feb-10 2:11 
Questionquery execution with mysql Pin
Guizzardi16-Feb-10 22:34
Guizzardi16-Feb-10 22:34 
AnswerRe: query execution with mysql Pin
OriginalGriff16-Feb-10 23:26
mveOriginalGriff16-Feb-10 23:26 
GeneralRe: query execution with mysql Pin
Guizzardi17-Feb-10 0:14
Guizzardi17-Feb-10 0:14 
GeneralRe: query execution with mysql Pin
OriginalGriff17-Feb-10 0:33
mveOriginalGriff17-Feb-10 0:33 
GeneralRe: query execution with mysql Pin
Guizzardi17-Feb-10 1:04
Guizzardi17-Feb-10 1:04 
GeneralRe: query execution with mysql Pin
OriginalGriff17-Feb-10 1:24
mveOriginalGriff17-Feb-10 1:24 
Guizzardi wrote:
Now I change the code like this:

MySqlConnection mysqlCon2 = new MySqlConnection(strProvider);
mysqlCon2.Open();
MySqlCommand mysqlCon2 = new MySqlCommand(strSQL);
mysqlCon2.ExecuteNonQuery();

Adding "2" to "mysqlCon" but now the error message is:

Error 1 A local variable named 'mysqlCon2' is already defined in this area...

referring to the third line...


Yes - because you have called both your MySqlConnection and your MySqlCommand by the same (new) name: "mysqlCon2". Now the compiler can't tell if you mean the Connection or the Command!

If you need to know if a query has been executed, then you want to get a mySQL front end application - there is SQLYog which I think has a free version - limited, but free. This lets you look at the database directly, and examine it's content.

The way I tend to do it (may not be the best, but it works):
MySqlCommand cmd = new MySqlCommand("DELETE FROM admin" +
                                    " WHERE IndexCollation=@IC");
cmd.Parameters.AddWithValue("@IC", strIndex);
Utilities.DoSQLNonQuery(cmd);
cmd = new MySqlCommand("INSERT INTO admin" +
                       " (IndexCollation, IndexManagement) " +
                       " VALUES (@IC, AES_ENCRYPT(@IN, @PW))");
cmd.Parameters.AddWithValue("@IC", strIndex);
cmd.Parameters.AddWithValue("@IN", username + "|" + password);
cmd.Parameters.AddWithValue("@PW", Credentials);
Utilities.DoSQLNonQuery(cmd);

/// <summary>
/// Execute a non-query on the database
/// </summary>
/// <remarks>A non-query is an INSERT, UPDATE, or similar instruction that does not require a reader.</remarks>
/// <param name="sqlCmd">Command to execute</param>
/// <returns>True if executed ok.</returns>
public static bool DoSQLNonQuery(MySqlCommand cmd)
    {
    string strConnect;
    bool bResult = false;
    try
        {
        strConnect = ConfigurationManager.ConnectionStrings["LoginDatabase"].ConnectionString;
        cmd.Connection = new MySqlConnection(strConnect);
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        bResult = true;
        }
    catch (Exception ex)
        {
        StringBuilder body = new StringBuilder("DoSQLNonQuery: " + cmd.CommandText + "\n");
        foreach (MySqlParameter par in cmd.Parameters)
            {
            body.Append(par.ParameterName + "=" + par.Value + "\n");
            }
        Log(body.ToString() + ex.ToString());
        }
    finally
        {
        if (cmd.Connection != null)
            {
            cmd.Connection.Close();
            }
        }
    return bResult;
    }
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace

GeneralRe: query execution with mysql Pin
Guizzardi17-Feb-10 3:05
Guizzardi17-Feb-10 3:05 
QuestionI have a cellclicked invent for my datagrid in a winform how do i automatically click it in code? Pin
tonyonlinux16-Feb-10 21:38
tonyonlinux16-Feb-10 21:38 
QuestionCreating Entity Class for XML Pin
K V Sekhar16-Feb-10 18:56
K V Sekhar16-Feb-10 18:56 
AnswerRe: Creating Entity Class for XML Pin
Saksida Bojan16-Feb-10 20:47
Saksida Bojan16-Feb-10 20:47 
GeneralRe: Creating Entity Class for XML Pin
kfqnwang9-Mar-11 16:00
kfqnwang9-Mar-11 16:00 
QuestionChat Server/Client Pin
satsumatable16-Feb-10 18:09
satsumatable16-Feb-10 18:09 
AnswerRe: Chat Server/Client Pin
Marcel Gheorghita16-Feb-10 19:05
Marcel Gheorghita16-Feb-10 19:05 
Questionmaths Pin
antrock10116-Feb-10 18:06
antrock10116-Feb-10 18:06 
AnswerRe: maths Pin
V.16-Feb-10 21:19
professionalV.16-Feb-10 21:19 
AnswerRe: maths Pin
harold aptroot16-Feb-10 23:29
harold aptroot16-Feb-10 23:29 
AnswerRe: maths Pin
OriginalGriff16-Feb-10 23:56
mveOriginalGriff16-Feb-10 23:56 
GeneralRe: maths Pin
antrock10117-Feb-10 3:59
antrock10117-Feb-10 3:59 
GeneralRe: maths Pin
antrock10117-Feb-10 4:13
antrock10117-Feb-10 4:13 
GeneralRe: maths Pin
antrock10117-Feb-10 11:30
antrock10117-Feb-10 11:30 
GeneralRe: maths Pin
antrock10119-Feb-10 17:42
antrock10119-Feb-10 17:42 
Questionw Pin
bahar316-Feb-10 17:50
bahar316-Feb-10 17:50 
Answerxyz Pin
Dan Mos16-Feb-10 18:38
Dan Mos16-Feb-10 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.