1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace WindowsFormsCommand
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- MySqlConnection conn;
- private void Form1_Load(object sender, EventArgs e)
- {
- conn = new MySqlConnection("server=localhost;database=dingdingeng;uid=root;pwd=abc123");
- conn.Open();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- if (conn.State == ConnectionState.Open || textBox1.Text != "")
- {
- MySqlCommand cmd = new MySqlCommand();
- 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);
- }
- }
- }
- }
|