Ajoyib! MySQL-yangilamasi xatosiz ishlamaydi

Quyida mening loyihamda hisob yaratish uchun kodim mavjud. Kod Response.Write (iduser) ga qadar ishlaydi, ammo UPDATE buyrug'i ishlamaydi. Istisnolardan foydalanib, hech qanday xato topilmadi, lekin MySQL-ning rekordi yangilanmaydi.

    try
                {

                    string pet1 = "[email protected]";
                    string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" + "SERVER=localhost;" + "DATABASE=newtest;" + "UID=root;" + "PASSWORD=**********;" + "OPTION=3";
                    OdbcConnection MyConnection = new OdbcConnection(MyConString);
                    OdbcCommand cmd = new OdbcCommand("Select id_user from awm_accounts where email=?", MyConnection);
                    cmd.Parameters.Add("@val1", OdbcType.VarChar, 255).Value = pet1;
                    MyConnection.Open();
                    OdbcDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows == false)
                    {
                        throw new Exception();
                    }
                    if (dr.Read())
                    {
                        int iduser = Convert.ToInt32(dr[0].ToString());
                        Account acct = new Account();
                        acct.Email = username.Text + domain.Text;
                        acct.MailIncomingLogin = username.Text + domain.Text;
                        acct.MailIncomingHost = "imap." + DropDownList1.SelectedValue;
                        acct.MailIncomingPassword = password.Text;
                        acct.MailIncomingPort = 993;
                        acct.MailOutgoingHost = "smtp." + DropDownList1.SelectedValue;
                        acct.MailOutgoingPort = 465;
                        acct.MailIncomingProtocol = IncomingMailProtocol.Imap4;
                        acct.MailOutgoingAuthentication = true;
                        acct.DefaultAccount = false;
                        acct.IDUser = 1;
                        integr.CreateUserFromAccount(acct);
                        Response.Write(iduser);
                        if (!IsPostBack)
                        {
                            cmd = new OdbcCommand("UPDATE awm_accounts SET id_user=? WHERE email=? ", MyConnection);
                            cmd.Parameters.Add("@tb_nickname", OdbcType.Int, 11).Value = iduser;
                            cmd.Parameters.Add("@tb_fullname", OdbcType.VarChar, 255).Value = username.Text + domain.Text;
cmd.ExecuteNonQuery();
                        }
                    }
                    MyConnection.Close();
                }
            catch (Exception exp)
            {
                Response.Write(exp);
            }
0
Yo'q. Ushbu kodda UpdatePanel dan foydalanmayapman.
qo'shib qo'ydi muallif Mad coder., manba
Buning yordamida UpdatePanel-ni ishlatasizmi? Agar shunday bo'lsa, xatoni tuzatmaguncha uni olib tashlang.
qo'shib qo'ydi muallif rlb.usa, manba

1 javoblar

Response.Write qismi haqida ishonchim komil emas, lekin ishonchingiz komilki, siz SQLCommand yaratasiz, lekin aslida uni hech qachon amalga oshirmaysiz.

Bu erda cmd.executeNonScalar() ni qo'yishni unutdingizmi?

2
qo'shib qo'ydi
Ha! Siz yozyapsiz. Hozirgina men cmd.executenonquery yo'qotilganimni topdim va kodni yaxshi ishladim. Rahmat.
qo'shib qo'ydi muallif Mad coder., manba