Sunday

C# - Database connection (SQLSERVER) by c sharp function

DBConnect();

using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;


protected void DBConnect()
{



System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = "Data Source=THOKR02-XP;Initial Catalog=OnDemand;Integrated Security=True";
conn.Open();

SqlCommand command = new SqlCommand("SELECT [TestSuite_Name] FROM [OnDemand].[dbo].[TestSuites]", conn);
SqlDataReader reader = command.ExecuteReader();
DropDownList1.Items.Clear();
while (reader.Read())
{

//TextBox2.Text = (String)reader[0];
DropDownList1.Items.Add((String)reader[0]);
}
reader.Close();
conn.Close();

}

No comments:

Post a Comment