I have two c# programms. the first one is inserting data to my databse. and the second one is reading from there. Here i have specially the problem with one action. the first programm is writting a status to the db (it's a MSSQL btw.). I have three columns in the db which i need:
The code for writting to the databse:
int k = WNR_KNR[1].Length;
int w = WNR_KNR[0].Length;
int s = status.Length;
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
string delete = "DELETE FROM Fertigung.dbo.Box" + boxnumber + "Status";
SqlCommand commanddel = new SqlCommand(delete, con);
commanddel.ExecuteNonQuery();
string query = "INSERT INTO Fertigung.dbo.Box" + boxnumber + "Status (WNR,KNR,status) VALUES ('" + WNR_KNR[0] +"','" + WNR_KNR[1] +"','"+status+"')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
Now when i write the strings have the right length for example the WNR_KNR1 has a length of 7.
The code from the programm that read now the status:
string sqlquery = "SELECT KNR, WNR, status FROM Fertigung.dbo.Box" + name + "Status";
SqlCommand com = new SqlCommand(sqlquery, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
KNR = reader["KNR"].ToString();
WNR = reader["WNR"].ToString();
status = reader["status"].ToString();
int k = KNR.Length;
int w = WNR.Length;
int s = status.Length;
}
Now when i read here the length from WNR_KNR1 is 10. And when i look at the string here there was added somae spaces to the string at the end. So when i write to the databse it's "working" and when i read it's "working ". From where are this spaces coming and why. And how to not get them. After reading from the db i'm doing an if query and yeah theres where i got the problem..