yokzu

yokzu

  • NA
  • 306
  • 0

Sending data to client

Dec 28 2009 7:13 PM
Hi.

I am getting data from accessdb with datareader. I want to all rows(datas) to send to client, but it doesnt work. All codes below. How can i do that?

--------------------------------------------------------------------

public void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
            Thread thread_dinleyici = new Thread(new ThreadStart(dinle_gonder));
            thread_dinleyici.Start();
            sunucu_bag.Open();
           
        }


 public void dinle_gonder()
        {
            TcpListener dinleyici = new TcpListener(30000);
            while (true)
            {
                dinleyici.Start();
                Socket istemcisoketi = dinleyici.AcceptSocket();
                karsi_ip = ((IPEndPoint)istemcisoketi.RemoteEndPoint).Address.ToString();
               
                if (!istemcisoketi.Connected)
                {
                    label2.Text = "Server is no connected";
                }
                else
                {

                    NetworkStream ag_akimi = new NetworkStream(istemcisoketi);

                    StreamReader akim_okuyucu = new StreamReader(ag_akimi);
                    string gelen_veri = akim_okuyucu.ReadLine();
                    textBox1.Text = gelen_veri;

                    // istemciden gelen veriyi db'ye yazdiriyoruz.
                    OleDbCommand cmd_veriyi_yaz = new OleDbCommand("INSERT INTO notlar (iletiler,tarih) VALUES ('"+gelen_veri+"' , '"+DateTime.Now+"')",sunucu_bag);
                    cmd_veriyi_yaz.ExecuteNonQuery();


                    // sending data to client

                    OleDbCommand cmd_veriyi_gonder = new OleDbCommand("SELECT iletiler,tarih FROM notlar", sunucu_bag);
                    OleDbDataReader rdr_gonderilecek;
                    rdr_gonderilecek = cmd_veriyi_gonder.ExecuteReader();

                    while (rdr_gonderilecek.Read())
                    {
                        Socket soket2 = dinleyici.AcceptSocket();
                        NetworkStream stream2 = new NetworkStream(soket2);

                        TcpClient istemci = new TcpClient(karsi_ip, 30001);
                        strieam2 = istemci.GetStream();
                        StreamWriter akim_yazici = new StreamWriter(stream2);
                        akim_yazici.WriteLine(rdr_gonderilecek["iletiler"].ToString(),rdr_gonderilecek["tarih"].ToString());
                        akim_yazici.Flush();
                    }

                }
            }


Answers (4)