using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.ComponentModel;
namespace DiaryApps
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new RegistrationForm());
// what am trying to do here is load the registration page once and to load the Login page for other subsequent logins
OleDbConnection newConnection;
OleDbCommand cmd = new OleDbCommand();
string Connection = @" provider=Microsoft.Jet.OLEDB.4.0; data source='Diarydatabase.mdb'; Jet OLEDB:Database Password= segunsco";
newConnection = new OleDbConnection(Connection);
newConnection.Open();
cmd.Connection = newConnection;
cmd.CommandText = "if exist(select Flag from createdDetails) begin select '1' else begin select '0' ";
OleDbDataReader MotReader = cmd.ExecuteReader();
if (MotReader.HasRows == true)
{
while (MotReader.Read())
{
string ty = MotReader.GetString(0);
if (ty == "")
{
Application.Run(new RegistrationForm());
}
if (ty == "1")
{
Application.Run(new Login());
}
newConnection.Close();
}
}
}
}
}
the problem here is that the initial page is always the login page even when my table is empty
Sameer BarathPosted May 23, 2013, 12:32 AM
now this method return things in the shape of object so we can unbox it as integer and use it in your code
OleDbConnection newConnection;
OleDbCommand cmd = new OleDbCommand();
string Connection = @" provider=Microsoft.Jet.OLEDB.4.0; data source='Diarydatabase.mdb'; Jet OLEDB:Database Password= segunsco";
newConnection = new OleDbConnection(Connection);
newConnection.Open();
cmd.Connection = newConnection;
cmd.CommandText = "if exist(select Flag from createdDetails) begin select '1' else begin select '0' ";
String strAns = cmd.ExecuteScaler().toString();
if (strAns == "0")
{
Application.Run(new RegistrationForm());
}
if (strAns == "1")
{
Application.Run(new Login());
}
newConnection.Close();
Hope this resolve your problem!!!!
Jignesh TrivediPosted May 23, 2013, 12:10 AM
try following code it might work for you.
cmd.CommandText = "if exist(select Flag from createdDetails) begin select '1' end else begin select '0' end";
OleDbDataReader MotReader = cmd.ExecuteReader();
if (MotReader.HasRows == true)
{
while (MotReader.Read())
{
string ty = MotReader.GetString(0);
if (ty == "0")
{
Application.Run(new RegistrationForm());
}
if (ty == "1")
{
Application.Run(new Login());
}
hope this will help you.