Hello I have got this code in class which runs 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;
}
}
}
In other forms I got SqlCommand or SqlDataAdapter and I need to add to them SqlConnection, but don't know how can I access them? Would you please suggest me something? for example this:
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM zajezd",);
SDA.Fill(dt);
SqlDataAdapter(string, SqlConnection)constructor?