1 usingSystem;2 usingSystem.Data;3 usingSystem.Text;4 usingSystem.Windows.Forms;5 usingSystem.Data.SqlClient;6 namespaceusehasrows7 {8 Public Partial classForm1:form9 {Ten PublicForm1 () One { A InitializeComponent (); - } - Private voidButton1_Click (Objectsender, EventArgs e) the { - Try - { -SqlConnection conn =NewSqlConnection ("server=.; Database=db_12;uid=sa;pwd="); + Conn. Open (); -SqlCommand cmd =NewSqlCommand ("SELECT * from"+TextBox1.Text.Trim (), conn); +SqlDataReader SDR =cmd. ExecuteReader (); A SDR. Read (); at if(SDR). HasRows) - { -MessageBox.Show ("there are values in the data table"+sdr[0]. ToString () +sdr[1]. ToString ()); - } - Else - { inMessageBox.Show ("There is no data in the data table"); - } to SDR. Close (); + Conn. Close (); - } the Catch(Exception ex) * { $ MessageBox.Show (ex. Message);Panax Notoginseng } - } the } +}
C # Read Database-sqldatareader () method