"Percubaan membaca semasa pembaca ditutup tidak memberi kesan."
P粉884667022
P粉884667022 2024-03-31 14:58:58
0
1
408

Saya cuba menulis data dari mysql uinlg c# ke fail .txt tetapi saya mendapat ralat "Percubaan baca tidak sah semasa pembaca ditutup.".

Kod ada di sini:

StreamWriter sr_Produto = new StreamWriter(@"C:\Enzo\PAP\PAP\Ficheiros\produto.txt", true);
            bdcon.Open();
            MySqlCommand cmd = new MySqlCommand("SELECT nome from produtos",bdcon);
            MySqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                sr_Produto.Write(dr["nome"].ToString());
            }
            bdcon.Close();
            bdcon.Open();
            StreamWriter sr_Quantidade = new StreamWriter(@"C:\Enzo\PAP\PAP\Ficheiros\quantidade.txt", true);
            MySqlCommand cmd1 = new MySqlCommand("SELECT quantidade from produtos_pedidos",bdcon);
            MySqlDataReader dr1 = cmd1.ExecuteReader();
            if (dr.Read())
            {
                sr_Produto.Write(dr["quantidade"].ToString());
            }
            bdcon.Close();
            bdcon.Open();
            StreamWriter sr_Subtotal = new StreamWriter(@"C:\Enzo\PAP\PAP\Ficheiros\subtotal.txt", true);
            MySqlCommand cmd2 = new MySqlCommand("SELECT subtotal from produtos_pedidos", bdcon);
            MySqlDataReader dr2 = cmd2.ExecuteReader();
            if (dr.Read())
            {
                sr_Produto.Write(dr["subtotal"].ToString());
            }
            bdcon.Close();
            bdcon.Open();
            StreamWriter sr_Valor = new StreamWriter(@"C:\Enzo\PAP\PAP\Ficheiros\valor.txt", true);
            MySqlCommand cmd3 = new MySqlCommand("SELECT valor from produtos");
            MySqlDataReader dr3 = cmd3.ExecuteReader();
            if (dr.Read())
            {
                sr_Produto.Write(dr["valor"].ToString());
            }
            bdcon.Close();

Saya akan gembira jika seseorang boleh membantu saya.

P粉884667022
P粉884667022

membalas semua(1)
P粉121081658

Jika anda melihat kod, anda sedang mencipta MySqlDataReader dr 并加载它,然后关闭它并创建并加载 MySqlDataReader dr1。然后,您尝试读取已关闭的 dr . Nampaknya anda juga mungkin cuba menulis kepada StreamWriter yang salah.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan