在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Data; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace CommandThreeProperties { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SqlConnection conn; private void Form1_Load(object sender, EventArgs e) { conn = new SqlConnection("server=.;database=db_12;uid=sa;pwd=sa"); conn.Open(); } private void button1_Click(object sender, EventArgs e) { try { if (conn.State == ConnectionState.Open || textBox1.Text != "") { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select count(*) from " + textBox1.Text.Trim(); cmd.CommandType = CommandType.Text; int i = Convert.ToInt32(cmd.ExecuteScalar());//返回查询结果的第一行第一列 label2.Text = "数据表中共有:" + i.ToString() + "条数据"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论