Memnoch1207
Sep 29th, 2003, 03:23 PM
The code below keeps generating the following error and I don't know why???
testDatabaseModules.cs(28,6): error CS0246: The type or namespace name 'myConnection' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
class Database
{
public static void db_open(string ConnectionStringPayload)
{
if(ConnectionStringPayload == "")
MessageBox.Show("Connection Error.", "Invalid Connection String", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
try
{
SqlConnection myConnection = new SqlConnection(ConnectionStringPayload);
myConnection.Open();
}
catch
{
MessageBox.Show("Connection Error", "Cannot connect to database, please check the connection string.");
}
}
public static string db_state()
{
string state = "";
if(myConnection.State.ToString() == "Open") ' errors here
state = "Open";
else
state = "Closed";
return state;
}
public static void Main()
{
string myConnectionString = ("server=localhost;database=pubs;user id=xxx;password=xxx;");
db_open(myConnectionString);
Console.WriteLine("Connection State: " + db_state());
}
}
testDatabaseModules.cs(28,6): error CS0246: The type or namespace name 'myConnection' could not be found (are you missing a using directive or an assembly reference?)
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
class Database
{
public static void db_open(string ConnectionStringPayload)
{
if(ConnectionStringPayload == "")
MessageBox.Show("Connection Error.", "Invalid Connection String", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
try
{
SqlConnection myConnection = new SqlConnection(ConnectionStringPayload);
myConnection.Open();
}
catch
{
MessageBox.Show("Connection Error", "Cannot connect to database, please check the connection string.");
}
}
public static string db_state()
{
string state = "";
if(myConnection.State.ToString() == "Open") ' errors here
state = "Open";
else
state = "Closed";
return state;
}
public static void Main()
{
string myConnectionString = ("server=localhost;database=pubs;user id=xxx;password=xxx;");
db_open(myConnectionString);
Console.WriteLine("Connection State: " + db_state());
}
}