dimanche 20 décembre 2015

How can I make 'score record' with database update?

I'm making millionaire game for my university project and i'm stuck in database part. Game asks the player name before game start. So i record to database as name/money. I can record the scores. But I want to change record if player(same name login) finish higher than before. And show this score in a label.(for show to player while he/she playing.) How can I do this? This code is working:

public void skorK()
        {

                    string gelenVeri = skor.veri;
                    string dbConnectionString = ("Data Source=sorular.db;Version=3;");
                    SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
                    try
                    {
                        sqliteCon.Open();
                        string Query = ("INSERT INTO skor(isim, puanSkor) VALUES ('" + gelenVeri + "', '" + mevcutPara + "')");
                        SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);
                        createCommand.ExecuteNonQuery();

I tried this. But I'm not even sure that it works. I think it does nothing:

string degistir = ("SELECT count(*) FROM skor WHERE isim='" + gelenVeri + "'");
                        SQLiteCommand createCommand2 = new SQLiteCommand(degistir, sqliteCon);
                            int isimDegis = Convert.ToInt32(createCommand2.ExecuteScalar());

                        if (isimDegis > 0)
                        {
                            string degistir2 = ("UPDATE skor SET isim='"+ gelenVeri +"', puanSkor='" + mevcutPara + "'");

                        } 

Aucun commentaire:

Enregistrer un commentaire