Is there any way to break the CommandText line below, so it's not one long string. I'm from an Access/VBA background where we use an & _ to wrap the text and make it more readable, but I can't figure how wrap it in c#...
Thanks in advance.
Roy.
private void btnLogin_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();
string user=userTxt.Text;
string password = passwordTxt.Text;
command.CommandText = "SELECT u.userID FROM Users AS u WHERE (((u.userName)='" + user + "') AND ((u.password)='" + password + "'));";
}
Ryan AlfordPosted Nov 27, 2007, 11:22 AM
old code:
command.CommandText = "SELECT u.userID FROM Users AS u WHERE (((u.userName)='" + user + "') AND ((u.password)='" + password + "'));";
new code:
StringBuilder cmdText = new StringBuilder();
cmdText.Append("SELECT u.userID ");
cmdText.Append("FROM Users AS u ";
cmdText.Append("WHERE (((u.userName)='" + user + "')");
cmdText.Append("AND ((u.password)='" + password +"'))");
command.CommandText = cmdText.ToString();
You could probably also clean up the SQL statement also without so many parenthesis.
maybe:
SELECT u.userID
FROM Users AS u
WHERE u.userName = '" + user + "' AND u.password = '" + password + "'