using System.Data;
using System.Data.SqlClient;
//Use all These Libararies If Your Connecting SqlServer
//Write These Codes In A Button Click Event Or A Function Or What Ever Event You Want To
#region Codes
string ConnectionString = @"Server=localhost;Database=dbName;Trusted_Connection=True";
SqlConnection connection = new SqlConnection(ConnectionString);
string commandtext = "Select CusNumber,CusName,CusLocation From Customer_Master";
SqlCommand command = new SqlCommand(commandtext,connection);
connection.Open();
SqlDataReader reader = comand.ExecuteReader();
ListBoxName.Items.Clear();//Code To Clear The Item Box When You Need It
while(reader.Read())
{
ListBoxName.Items.Add(reader[0].ToString()+" - "+reader[1].ToString+" - "+reader[2].ToString);
}
reader.Close();
connection.Close();
#endregion
No comments:
Post a Comment