Dec 7, 2013

C# Load To ListBox From SqlServer

using System;                  
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:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...