当前位置: 代码迷 >> ASP.NET >> 联接就是未初始化
  详细解决方案

联接就是未初始化

热度:8290   发布时间:2013-02-25 00:00:00.0
连接就是未初始化
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient;using System.Data;using System.Web;/// <summary>///Class1 的摘要说明/// </summary>///     public class Class1    {        public static Boolean login(String name,String pass)    {        SqlConnection MyConnection = new SqlConnection("server=.;uid=sa;pwd=yk_123;database=poject");        MyConnection.Open();        SqlCommand sql = new SqlCommand("select * from member where mname=@name and mpass=@pass");                                   SqlParameter pa = new SqlParameter("@name",SqlDbType.VarChar,50);        pa.Value =name;                    SqlParameter pa1 = new SqlParameter("@pass",SqlDbType.VarChar,50);        pa1.Value = pass;        sql.Parameters.Add(pa);        sql.Parameters.Add(pa1);        int rs = sql.ExecuteNonQuery();        if (rs > 0)        {            return true;        }        else        {            return false;        }                 }    }

怎么弄就是告诉我连接没有被初始化,疯了。。。

------解决方案--------------------------------------------------------
C# code
SqlConnection conn = new SqlConnection();SqlCommand cmd = new SqlCommand("sql", conn);
  相关解决方案