日期:2014-05-17 浏览次数:21370 次
string conn_str = @"Data Source=(local);Initial Catalog=数据库名;UserID=用户名;Password=密码"; string show_str = string.Empty; using (SqlConnection conn = new SqlConnection(conn_str)) { conn.Open(); string sql = string.Format("select * from Table where 序号='{0}'",this.textBox1.Text.Trim()); using (SqlCommand com = new SqlCommand(sql,conn)) { SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { show_str = string.Format("{0} {1} {2} {3}",dr[0].ToString(),dr[1].ToString(),dr[2].ToString(),dr[3].ToString()); } dr.Close(); dr.Dispose(); } } this.textBox2.Text = show_str;//显示