感谢您使用微软产品。经过在我的电脑上测试,没有发现错误。测试代码如下,供您参考:
private void btnRetrieve_Click(object sender, System.EventArgs e)
{
dataGrid1.DataSource = CreateDataSource();
}System.Collections.ICollection CreateDataSource()
{
string mys="select * from friends";
string myc="server=SHA-RICKIE-01;uid=user;pwd=user;database=test";
SqlConnection myconn=new SqlConnection(myc);
SqlDataAdapter mycomm=new SqlDataAdapter(mys,myconn);
DataSet tr=new DataSet();
mycomm.Fill(tr,"friends");
return tr.Tables["friends"].DefaultView;
}
问题有可能是由于:string myc="server=SHA-RICKIE-01;uid=user;pwd=user;database=test";中的服务器名,用户名,口令等存在错误;
测试系统配置:
Windowx XP Professional
Visual Studio.Net 2002 Version 7.0.9466
Microsoft .NET Framework 1.0 Version 1.0.3705 — 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。