Hi
Login is getting loaded but not showing message . Below are the Forms
C#
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
public partial class Login : Form
{
SqlCommand cmd;
SqlConnection cn;
SqlDataReader dr;
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
MessageBox.Show("connecting with sql server");
SqlConnection cnn = DatabaseConnection.GetInstance();
//execute queries
string query = "SELECT * FROM Login";
SqlCommand command = new SqlCommand(query, cnn);
cnn.Open();
DataSet ds = new DataSet();
MessageBox.Show("connect with sql server");
}
private void Btnregister_Click(object sender, EventArgs e)
{
//this.Hide();
////Registration registration = new Registration();
//registration.ShowDialog();
}
}
Thanks

Jignesh KumarRank #91 · 22.9K reputationPosted Aug 14, 2024, 9:11 AM EDT
Hello Ramco,
Could you please try below code,
try { MessageBox.Show("Connecting with SQL Server..."); // Get the singleton connection instance SqlConnection cnn = DatabaseConnection.GetInstance(); // Execute queries string query = "SELECT * FROM Login"; SqlCommand command = new SqlCommand(query, cnn); // No need to open the connection here if it's already open // If connection is not open, you can check and open it if (cnn.State == ConnectionState.Closed) { cnn.Open(); } // You can load data into a dataset if needed (though not shown in your original code) DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(ds); MessageBox.Show("Connected to SQL Server successfully."); } catch (Exception ex) { // Show error message if there's an exception MessageBox.Show("An error occurred: " + ex.Message); }Ramco RamcoRank #462 · 5.4K reputationPosted Aug 14, 2024, 9:18 AM EDT
Hi Jignesh
I tried this . Buttin is getting displayed in Login Form. I think it is not going in
Login_Load function
Thanks