0
Reply

Textbox values of server program not update ?

Ask a question
Member1

Member1

9y
559
1
I have a text box in server program and when client connected and request server for some information server program works but did not put sentences on text box after work done but this works on console screen but not on form , this is line on code which i am trying to execute,
 
here is my code,
 
public void getdata()
try
{
Program pq = new Program();
string ipadd = getip();

// IPAddress ipAd = IPAddress.Parse("192.168.0.10"); //use local m/c IP address, and use the same in the client
IPAddress ip = IPAddress.Parse(ipadd);
txtip.Text = Convert.ToString(ip);
txtport.Text = "3030";
/* Initializes the Listener */
TcpListener myList = new TcpListener(IPAddress.Any, 3030);

/* Start Listeneting at the specified port */

myList.Start();

txtdata.Text = txtdata.Text + Environment.NewLine +"The server is running at port 3030...";
txtdata.Text = txtdata.Text + Environment.NewLine +"The local End point is :" + myList.LocalEndpoint;
txtdata.Text = txtdata.Text + Environment.NewLine +"Waiting for a connection.....";

Socket s = myList.AcceptSocket();


txtdata.Text = txtdata.Text + Environment.NewLine +"Connection accepted from " + s.RemoteEndPoint;

for (int p = 0; p >= 0; p++)
{
byte[] b = new byte[100];

int k = s.Receive(b);

txtdata.Text = txtdata.Text + Environment.NewLine +"Recieved...";

for (int i = 0; i < k; i++)
{
txtdata.Text = txtdata.Text + Environment.NewLine +Convert.ToChar(b[i]);
}

var j = b.Length - 1;
while (b[j] == 0)
{
--j;
}

var temp = new byte[j + 1];
Array.Copy(b, temp, j + 1);

string result = System.Text.Encoding.ASCII.GetString(temp);

SqlCommand cmd = new SqlCommand("SELECT Barcode,Product,Packing,[Mfg.],Batch,Expiry," +
"MRP,[Tot.Qty],[MRP Value (Rs)] FROM MD where [Barcode] ='" + result + "'", con);

DataTable table = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(table);

// Now you have a collection of rows that you can iterate over
foreach (DataRow row in table.Rows)
{
string barcode = row["Barcode"].ToString();
string product = row["Product"].ToString();
string packing = row["Packing"].ToString();
string mfg = row["Mfg."].ToString();
string batch = row["Batch"].ToString();
string expiry = row["Expiry"].ToString();
string mrp = row["MRP"].ToString();
string totq = row["Tot.Qty"].ToString();
string mrpvalue = row["MRP Value (Rs)"].ToString();

string[] sqldata = { product, packing, mfg, batch, expiry, mrp, totq, mrpvalue };

ASCIIEncoding asen = new ASCIIEncoding();

for (int i = 0; i < sqldata.Length; i++)
{

s.Send(asen.GetBytes(sqldata[i]));
s.Send(asen.GetBytes(","));
}
s.Send(asen.GetBytes("#"));
txtdata.Text = txtdata.Text + Environment.NewLine +"\n Sql Data Sent!!!";
}
}
txtdata.Text = txtdata.Text + Environment.NewLine +"\nSent Acknowledgement";
txtdata.Text = txtdata.Text + Environment.NewLine +"Client connected and data sent" ;
/* clean up */
s.Close();
myList.Stop();
}
 

Next Recommended Forum