您好,我在运行 SqlConnection 的类中有此代码:
using System.Data.SqlClient;
using System.IO;
namespace tours
{
class myConnection
{
public static SqlConnection GetConnection()
{
string path = "C:\\Users\\marek\\Documents\\Visual Studio 2012\\Projects\\tours\\tours\\sql_string.txt";
StreamReader sr = new StreamReader(File.Open(path, FileMode.Open));
string str = "Data Source='" + sr.ReadLine() + "';Initial Catalog ='" + sr.ReadLine() + "' ;User ='" + sr.ReadLine() + "';Password = '" + sr.ReadLine() + "'";
SqlConnection spojeni = new SqlConnection(str);
spojeni.Open();
return spojeni;
}
}
}
在其他形式中,我得到SqlCommand
或SqlDataAdapter
我需要添加到它们SqlConnection
,但不知道如何访问它们?你能给我一些建议吗?例如这个:
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM zajezd",);
SDA.Fill(dt);