关于初始化字符串的格式不符合规范。
public SqlDataReader GetList(string Sql){
SqlConnection myConnection = new SqlConnection(Db.ConnectionString);
SqlCommand myCommand = new SqlCommand(Sql, myConnection);
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return result;
}
其中“SqlConnection myConnection = new SqlConnection(Db.ConnectionString);”老提示索引90后,初始化字符串的格式不符合规范,请大侠帮帮小弟吧 --------------------编程问答-------------------- 显然是连接字符串没写对.自己查
http://connectionstrings.com/ --------------------编程问答-------------------- 字符串不对
string ConnectionString = "data source=localhost;initial catalog=DatabaseName;integrated security=SSPI;user ID=sa;password=123456"; --------------------编程问答-------------------- Db.ConnectionString 是从哪里读取的,查看原链接字符串是否正确! 字符串连接如楼上的。 --------------------编程问答--------------------
--------------------编程问答-------------------- public class Database
public SqlDataReader GetList(string Sql)
{
string ConnectionString = "data source=localhost;initial catalog=DatabaseName;integrated security=SSPI;user ID=sa;password=123456";
SqlConnection myConnection = new SqlConnection(ConnectionString);
SqlCommand myCommand = new SqlCommand(Sql, myConnection);
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return result;
}
{
protected string strconnection;
protected SqlConnection conn;
public Database()
{
strconnection = ConfigurationManager.ConnectionStrings["zilong"].ConnectionString;
}
protected void Open() //保护方法,打开连接
{
if (conn == null)
{
conn = new SqlConnection(strconnection);
}
if (conn.State.Equals(ConnectionState.Closed))
{
conn.Open();
}
}
public void Close()
{
if (conn.State.ToString() == "Open")
{
conn.Close();
}
}
public SqlDataReader GetList(string Sql)
{
Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return result;
}
--------------------编程问答--------------------
顶
补充:.NET技术 , ASP.NET