luciddream
Programmer
i've been having a problem that doesn't make any sense to me. i've been trying to put a variable in a string, but, the string always cuts off at the end of the variable..
i hope someone has had this problem before and can help me out. the variable i'm trying to put in the string is a substring of data that is read from a socket. i've tried everything i can think of to try to get around this problem.. (renaming the variables, trimming it, making a char array out of it then joining it together.. the problem remains.)
this is what my code originally looked like:
the problem is with the sql query.. after uid, it won't concatenate the "')" and i get a sql error.
the code that calls this is :
if anyone can help me, i'd greatly appreciate it.
adam@croem.net
i hope someone has had this problem before and can help me out. the variable i'm trying to put in the string is a substring of data that is read from a socket. i've tried everything i can think of to try to get around this problem.. (renaming the variables, trimming it, making a char array out of it then joining it together.. the problem remains.)
this is what my code originally looked like:
Code:
private string uid;
private void doLogin(string com)
{
uid = com.Substring(1);
sqlCmd.CommandText = "insert into print_users (cc_index,ip,uid) Values("+index.ToString()+",'"+mySocket.RemoteEndPoint.ToString()+"','"+uid+"')";
try
{
sqlCmd.ExecuteNonQuery();
}
catch(Exception e)
{
rtb.Text += e.Message+" from "+mySocket.RemoteEndPoint.ToString()+"\n";
}
}
the problem is with the sql query.. after uid, it won't concatenate the "')" and i get a sql error.
the code that calls this is :
Code:
public void HandleThread()
{
Thread currentThread = Thread.CurrentThread;
mySocket = myTcpListener.AcceptSocket();
rtb.Text += "Connection from "+mySocket.RemoteEndPoint.ToString()+"\n";
while(boo)
{
if(mySocket.Available>0)
{
byte[] buffer = new byte[1024];
string command = string.Empty;
int avail = mySocket.Available;
int read = mySocket.Receive(buffer,0,avail,SocketFlags.None);
command = Encoding.ASCII.GetString(buffer);
rtb.Text += command+"\n";
switch(command.Trim().Substring(0,1))
{
case "K":
boo = false;
break;
case "L":
doLogin(command);
break;
case "A":
keepAlive();
break;
default:
break;
}
}
else
{
Thread.Sleep(1000);
}
}
doLogout();
mySocket.Shutdown(SocketShutdown.Both);
mySocket.Close();
rtb.Text += "Connection Closed\n";
currentThread.Abort();
}
if anyone can help me, i'd greatly appreciate it.
adam@croem.net