Date: 12/07/07 (Web Development) Keywords: database, sql How do I get a datareader to compare a number entered in a text box with the information in a database? I have the datareader connected, but I think the problem may lie in my SQL statement: here's the whole code: Session.Add("Quantity", txtQuantity.Text); //Adds the info in txtQuantity.Text to a session, for later use. //there is already an exception that checks if a user entered a number or letter //...no worries there. OleDbConnection conn = new OleDbConnection((string)Application["DBConnectionString"]); OleDbDataReader qdr = null; //the value of qdr is originally null, will get filled later. // Query string concatenates fixed text with the user's selection string qtyString = "SELECT Products.UnitsInStock " + "FROM Products " + "WHERE Products.UnitInStock ="; //+ //int.Parse(Session["Quantity"].ToString()); // OleDbDataAdapter da = new OleDbDataAdapter(); OleDbCommand cm = new OleDbCommand(qtyString, conn); conn.Open(); qdr = cm.ExecuteReader(); //Since I have a "where Products.UnitInstock =", I get an error that qdr is still null. /*I suspect my comparison would go somewhere here, but I am unsure how to write a comparison of a textbox value to qtyString (or if there is another better way of comparing the two. */ qdr.Close(); conn.Close(); thanks :). PS formatting sucks cos I disabled the richtext editor.
|