Testing_C# 发表于 2014-8-27 17:18:01

这里为什么会错呢

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace demo_Builder1
{
    public partial class Form1 : Form
    {
      SqlConnection connection=new SqlConnection();
      SqlCommand command=new SqlCommand();
      SqlDataReader reader;
      public Form1()
      {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
      }

      private void Form1_Load(object sender, EventArgs e)
      {

      }

      private void button1_Click(object sender, EventArgs e)
      {
            connection.ConnectionString = "Data Source=.;Initial Catalog=Test_QQ;User ID=test;Password=1";
            command.Connection = connection;
            string temp= string.Format("selectcount(*) from QQ_User where USER_NAME='{0}' and User_Password='{1}'", this.textBox1.Text, this.textBox2.Text);
            command.CommandText = temp;
            command.CommandType = CommandType.Text;

            try
            {
                connection.Open();
               // MessageBox.Show("数据库打开成功");
                int test =Convert.ToInt32(command.ExecuteNonQuery());
                if (test>0)
                {
                  MessageBox.Show("登陆成功");
                }
                else
                {
                  MessageBox.Show("登陆失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("数据库异常"+ex);
            }
            finally
            {
                connection.Close();
            }
      }

      private void button2_Click(object sender, EventArgs e)
      {
            Application.Exit();
      }
    }
}


ibcadmin 发表于 2014-8-27 19:14:43

哪里出错?哪行

Testing_C# 发表于 2014-8-27 21:57:07

ibcadmin 发表于 2014-8-27 19:14
哪里出错?哪行

下午已经自己解决了 谢谢admin
页: [1]
查看完整版本: 这里为什么会错呢