日期:2014-05-17  浏览次数:20642 次

求教大侠们 出错了
本帖最后由 jyfyzhi 于 2013-03-26 17:38:28 编辑
小白学到了ado.net   验证用户名和密码登陆数据库  敲了这段代码  可是出错了 但自己不知道出在哪里 怎么改
 谢谢老大们

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplicati
{
? ? class DBOption
? ? {
? ? ? ? private string sqlstring = "server=.;database=student;uid=sa;pwd=333333";




? ? ? ? public string Sqlstring//封装连接字符串
? ? ? ? {
? ? ? ? ? ? get { return sqlstring; }
? ? ? ? }
? ? ? ? private SqlConnection connection;




? ? ? ? public SqlConnection Connection//封装连接对象
? ? ? ? {
? ? ? ? ? ? get
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (connection == null)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? connection = new SqlConnection(Sqlstring);
? ? ? ? ? ? ? ? ? ? //创建连接对象
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return connection;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? public void OpenConnection()
? ? ? ? {//打开连接
? ? ? ? ? ? if (Connection.State == ConnectionState.Closed)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Connection.Open();
? ? ? ? ? ? }
? ? ? ? ? ? else if (Connection.State == ConnectionState.Broken)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Connection.Close();
? ? ? ? ? ? ? ? Connection.Open();
? ? ? ? ? ? }




? ? ? ? }
? ? ? ? public void CloseConnection()
? ? ? ? { //关闭连接
? ? ? ? ? ? if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Connection.Close();
? ? ? ? ? ? }
? ? ? ? }




? ? }
? ? class Program
? ? {
? ? ? ? public bool LoginAction(string id, string pwdd)
? ? ? ? {//登录方法
? ? ? ? ? ? DBOption dbp = new DBOption();
? ? ? ? ? ? dbp.OpenConnection();
? ? ? ? ? ? SqlCommand sqlcom = new SqlCommand();
? ? ? ? ? ? sqlcom.Connection = dbp.Connection;
? ? ? ? ? ? sqlcom.CommandText =&n