给你一个例子:对照一下就会了 SqlConnection conn= new SqlConnection("Data Source=localhost;Database=northwind;Uid=sa;Pwd=;");
SqlDataAdapter adapter= new SqlDataAdapter("select * from Customers",conn);
DataSet myDataSet= new DataSet();
try
{
adapter.Fill(myDataSet,"Customer");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
SqlDataAdapter adapter= new SqlDataAdapter("select * from Customers",conn);
DataSet myDataSet= new DataSet();
try
{
adapter.Fill(myDataSet,"Customer");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
这句右问题
string f_Con="FILE NAME="+Application.StartupPath +"\\" +"Conn.udl";
你调试一下f_Con的值是不是正确的路径
SqlConnection的连接字符串,不用指出路径的,只需指出库名 登录名 密码 服务器名
user id=用户名(一般用 sa);
password=" 口令;
initial catalog=連接数据库名称
如果你用的是Access的库或其他本地数据库,应该用OleDbConnection进行连接
SqlConnection f_Conn=new SqlConnection(f_Con);
麻烦你们在网上搜索一下"C# udl数据连接"就知道什么叫udl了,不要以为掌握了一个SQL Server数据库连接,就什么都知道了
using System.Data;
using System.Data.OleDb;
就OK Pass 了!
谢谢大家的帮忙!