Calling Data data in textbox ok but i have backspace number to stop and error Please Help Me RRS feed

  • Question


    stringconnString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;

    stringcmdString = "SELECT * FROM tblBasicInfo WHERE ID ="+Convert.ToInt32(IDtextBox.Text);

    using(OleDbConnectionconn = newOleDbConnection(connString))


    using(OleDbCommandcmd = newOleDbCommand(cmdString, conn))



    OleDbDataReaderreader = cmd.ExecuteReader();



    SttextBox.Text = (reader["SName"].ToString());

    FaNametextBox.Text = (reader["FName"].ToString())

    Friday, February 16, 2018 6:40 AM

All replies

  • Where is your error and what is your error? And, it's not clear what you mean by "have backspace number to stop".


    Oh, one more thing ... on the off-chance that the error has to do with converting IDTextBox.Text to an int, you should always use a TryParse with user-entered data. Something like this:

    int ID;
    // This is assuming you don't want to do anything with a zero ID, which is what the 
    // TryParse will default to if it the input text is not a valid int.
    if (int.TryParse(IDtextBox.Text, out ID) == false)
    string cmdString = "SELECT * FROM tblBasicInfo WHERE ID =" + ID;

    Normally I advocate always using parameters, but in this case you wouldn't need to because you know your ID will be a valid integer.

    ~~Bonnie DeWitt [C# MVP]


    • Edited by BonnieBMVP Saturday, February 17, 2018 5:36 PM added more info
    Saturday, February 17, 2018 5:22 PM
  • I updated my previous reply ...

    ~~Bonnie DeWitt [C# MVP]


    Saturday, February 17, 2018 5:36 PM