protected void Page_Load(object sender, EventArgs e) { } protected void btnGet_Click(object sender, EventArgs e) { { //1. build the connection string for our SQL instance string connectionString = "Data Source=LA-HPENVY15;Initial Catalog=CryptoText;Integrated Security=True"; //2. build the connection to our SQL instance using (SqlConnection con = new SqlConnection(connectionString)) { //open the connection con.Open(); //string variable to hold the ouput string result = String.Empty; //3. Build our SQL query SqlCommand cmd = new SqlCommand("SELECT TOP 1 Cipher FROM CipherText ORDER BY NEWID()", con); //4. Execute the query SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //add the results from the SQL query to a textbox result = reader["Cipher"].ToString(); txtGet.Text += result; } //5. Always close connections when you're done con.Close(); } } } } }
txtGet.Text += result;
txtGet.Text = result;
protected void Page_Load(object sender, EventArgs e) { txtGet.Text = ""; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)