I make this 2 methods that return a SQLConnection, the first one is for SQL
Server Security Scheme and the second is for Integrated Security Scheme.
public static SqlConnection ConnectToSQL(string server, string database,
string user, string password)
{
string connectionstring = "server=" + server.Trim() + ";";
connectionstring += "uid=" + user + ";";
connectionstring += "pwd=" + password + ";";
connectionstring += "database=" + database.Trim() + ";";
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
return connection;
}
public static SqlConnection ConnectToSQL(string server, string database)
{
SqlConnection nwindConn = new SqlConnection();
string connectionstring = "Data Source=" + server.Trim() + ";Integrated
Security=SSPI;Initial Catalog=" + database.Trim() + ";";
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
return connection;
}
If this works fine then create the DataSet.
DataSet ds = new DataSet("Test");
string sql = "SELECT * FROM Item";
(new SqlDataAdapter(sql, connection)).Fill(ds, "Item");
After that, the DataSet ds should have the table and records. If you want
read the records, you could use:
foreach(DataRow row in dsClientes.Tables["Cli_Clientes"].Rows)
{
MessageBox.Show(row["fieldname"].ToString())
}
Hope this help you.
Reb said:
Hi,
I am actually getting to know about the code written by
another person.
There are many files involved with this.
He has used typed dataset and has written all the sql
statements in the InitializeComponent() in the start page.