日期:2014-05-18  浏览次数:20421 次

sqlconnection连接字符串的问题
大家帮我看看,郁闷了一下午了,总是说这里未将对象引用设置到对象的实例
"Server=localhost;Database=WeatherWorks;uid=sa;pwd= "

------解决方案--------------------
这样改下:
"Server=(local);Database=WeatherWorks;uid=sa;pwd= "

不过,报这个错,应该不是因为这个连接字符串不正确造成的.你看一下是不是有其它的原因.
------解决方案--------------------
上面的没错啊。!!!!!!!!!!

还是看看我的吧
static string strcnn = "Persist Security Info=False;User ID=sa;Initial Catalog=Aino;Data Source=UNIT-5H8B1JHORU\\AINO ";

/// <summary>
/// 返回信息
/// </summary>
/// <returns> DataTable </returns>
public static DataTable GetOrderInfo()
{
SqlConnection cnn = new SqlConnection(strcnn);
cnn.Open();
string strcmm = "select * from tOrder ";
SqlCommand cmm = new SqlCommand(strcmm,cnn);

//返回结果集
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmm);
da.Fill(dt);
cnn.Close();
return dt;
}