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

C#

 
GeneralRe: Regular expression Pin
salmonraju16-Feb-10 23:24
salmonraju16-Feb-10 23:24 
GeneralRe: Regular expression Pin
OriginalGriff16-Feb-10 23:30
mveOriginalGriff16-Feb-10 23:30 
GeneralRe: Regular expression Pin
salmonraju16-Feb-10 23:46
salmonraju16-Feb-10 23:46 
QuestionXmlSerializer doesn't serialize properties when inheriting List<T>? [modified] Pin
mav.northwind16-Feb-10 22:55
mav.northwind16-Feb-10 22:55 
AnswerMessage Closed Pin
16-Feb-10 23:08
stancrm16-Feb-10 23:08 
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 
Hi,

i'm very new about c# but, I need to change a little program using VC#2005 + MySQL.

The following code works well. My problem is insert a second query to make an INSERT into the DB.

void Cmd_Login_Click(object sender, EventArgs e)
        {

            string host = "localhost";
            string database = "database";
            string user = "username";
            string password = "password";

            string strSQL = "SELECT * FROM users";

            string strProvider = "Data Source=" + host + 
                                ";Database=" + database + 
                                ";User ID=" + user + 
                                ";Password=" + password;
            try
            {
                MySqlConnection mysqlCon = new MySqlConnection(strProvider);
                mysqlCon.Open();

                if (mysqlCon.State.ToString() == "Open")
                {
                    MySqlCommand mysqlCmd = new MySqlCommand(strSQL, mysqlCon);
                    MySqlDataReader mysqlReader = mysqlCmd.ExecuteReader();

                    while (mysqlReader.Read())
                    {
                        if (Txt_Name.Text == mysqlReader.GetString(1) && Txt_Code.Text == mysqlReader.GetString(2))
                        {

                            <big></big>//POINT TO INSERT QUERY TO EXECUTE

                            if (checkBox1.Checked )
                            {
                                Frm_Main Frm_Main = new Frm_Main();
                                Frm_Main.Close();

                                Form1 form1 = new Form1();
                                form1.ShowDialog();
                            }
                            else
                            {
                                Pan_Step1.Visible = false;
                                Closer.Start();
                            }
                        }
                    }
                }
                    else 
                    {
                        System.Media.SystemSounds.Hand.Play();
                    }

                mysqlCon.Close();

            }
            catch (Exception er)
            {
                Console.WriteLine("Errore " + er.Message);
            }
        }


The query to insert into the code is like this:

strSQL = "UPDATE users SET access='" + DateTime.Now.ToString() + "', admin='" + checkBox1.CheckState + "' WHERE username='" + mysqlReader.GetString(1) + "'";

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


This code mean that if I write the right access account the query update the DB information about the last access.

Obviously I receive back a lot of errors.

Someone can help me to write the right code so I understand the mistake?
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 
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 

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.