D
Dan
I'm using several forms to manipulate several database tables, with
child objects and relations.
I've created classes for my Company records with properties for each
field in the table (gets and sets), but I can't seem to figure out how
to load the class with the data. I can create a method in the Company
class, but then I have to create a variable from the class to add the
field values to, then how do I get that variable out to the form.
It's wring and I know it, but I can't find any help in the books I
have, becuase all the example I can find do it all in one class and
method (Main()).
I think I want the method to run against the class and not a variable
in the class, but how do I reference the DB with varaibles? Here is
the code I'm using now:
I don't currently have this in the Company class as I got errors
trying to reference the class in itself (using 'this')
I'm only posting 2 of the Company properties classes, otherwise it's
just too long
public static void FillCompany(string CompID)
{
SqlConnection myDB =
new SqlConnection("server=SQLDB.RL.INT;database=" +
"Subs_Dev;Integrated Security=SSPI;");
SqlCommand mySQLCommand = myDB.CreateCommand();
Company myCompany = new Company();
string selectString = "EXEC uspSearchID @ID=" + CompID
+ ", @Table=utblcompany";
mySQLCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySQLCommand;
DataSet myDataset = new DataSet();
try
{
myDB.Open();
}
catch
{
}
string dataTableName = "Company";
mySqlDataAdapter.Fill(myDataset, dataTableName);
DataTable myDataTable = myDataset.Tables[dataTableName];
DataRow myDataRow = myDataTable.Rows[0];
myCompany.ActiveSubFlag = myDataRow
["ActiveSubFlag"].ToString();
}
public class Company
{
private Int32 orgID;
private string activesubflag;
public Int32 OrgID
{
get
{
return orgID;
}
set
{
orgID = value;
}
}
public string ActiveSubFlag
{
get
{
return activesubflag;
}
set
{
activesubflag = value;
}
}
}
child objects and relations.
I've created classes for my Company records with properties for each
field in the table (gets and sets), but I can't seem to figure out how
to load the class with the data. I can create a method in the Company
class, but then I have to create a variable from the class to add the
field values to, then how do I get that variable out to the form.
It's wring and I know it, but I can't find any help in the books I
have, becuase all the example I can find do it all in one class and
method (Main()).
I think I want the method to run against the class and not a variable
in the class, but how do I reference the DB with varaibles? Here is
the code I'm using now:
I don't currently have this in the Company class as I got errors
trying to reference the class in itself (using 'this')
I'm only posting 2 of the Company properties classes, otherwise it's
just too long
public static void FillCompany(string CompID)
{
SqlConnection myDB =
new SqlConnection("server=SQLDB.RL.INT;database=" +
"Subs_Dev;Integrated Security=SSPI;");
SqlCommand mySQLCommand = myDB.CreateCommand();
Company myCompany = new Company();
string selectString = "EXEC uspSearchID @ID=" + CompID
+ ", @Table=utblcompany";
mySQLCommand.CommandText = selectString;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySQLCommand;
DataSet myDataset = new DataSet();
try
{
myDB.Open();
}
catch
{
}
string dataTableName = "Company";
mySqlDataAdapter.Fill(myDataset, dataTableName);
DataTable myDataTable = myDataset.Tables[dataTableName];
DataRow myDataRow = myDataTable.Rows[0];
myCompany.ActiveSubFlag = myDataRow
["ActiveSubFlag"].ToString();
}
public class Company
{
private Int32 orgID;
private string activesubflag;
public Int32 OrgID
{
get
{
return orgID;
}
set
{
orgID = value;
}
}
public string ActiveSubFlag
{
get
{
return activesubflag;
}
set
{
activesubflag = value;
}
}
}