在 System.ArgumentException 中第一次偶然出现的“System.Data.dll”类型的异常
代码如下:using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "myQQ";
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("没睡醒呢吧您类!还真当我是万能的啦!");
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text == "" || comboBox1.Text == "")
MessageBox.Show("账号或密码不能为空!");
else
{
string connectionString = String.Format("Data Source=localhost;Iniyial Catalog=QQ;Integrated Security=true");
//创建connection对象
SqlConnection conn = new SqlConnection(connectionString);
//编写sql语句
string sql = string.Format("Select 账号,密码 from 注册表 ");
//创建command对象
SqlCommand command = new SqlCommand(sql, conn);
//打开连接
conn.Open();
//创建sqldatareader对象用来读取数据库内容
SqlDataReader read = command.ExecuteReader();
//执行查询(这里的查询为把数据库中为fontname的列的所有值加入textBox1中)
if (comboBox1.Text == read["账号"].ToString())
{
if (textBox2.Text == read["密码"].ToString())
{
登陆成功 dl = new 登陆成功();
dl.Show();
this.Close();
}
}
else
MessageBox.Show("密码错误!");
//关闭对象和数据库连接
read.Close();
conn.Close();
}
}
}
}