Ok I have a person class and a files class to output to a database.
the question I have is if person has name, and address for example
can I pass person object instead of each individual item in the class?
public class Person
{
private string Name;
private string Address;
}
a function in my files class would be something like this abreviation
public void Personrecord(Pe rson)
INSERT INTO Personrecord (" + "Name , Address "+")
VALUES (' "+Name + " ' , ' " + Address +" ' )";
how can I pass a person instead of each variable, Name and Address?
It is hard for a nube since I am not sure "Exactly" how to ask this.
thank you for any and all help
Jerry 5 1192
Hi Jerry,
You should be able to pass Person to the database, but you need to
create a single chunk of data out of it before you do, for instance
using serializing. http://msdn.microsoft.com/library/en...ingobjects.asp
You might also just create a ToString method in your Person class
that gives you a string consisting of a name and address and put
that in the database. Something like this:
public class Person
{
private string Name;
private string Address;
public override string ToString()
{
return Name + "\t" + Address;
}
}
Splitting the value in the database at the tab character will
give you name and address.
--
Happy Coding!
Morten Wennevik [C# MVP]
Well you can pass a class reference easily to a function, but your problem
is accessing the fields since you have made them private. You can make them
public or define properties for each.
e.g. (if they are public fields)
public void Personrecord(Pe rson per)
{
something=per.N ame; etc.
}
Thomas P. Skinner [MVP]
"sparks" <jo***@lost.net > wrote in message
news:i1******** *************** *********@4ax.c om... Ok I have a person class and a files class to output to a database. the question I have is if person has name, and address for example can I pass person object instead of each individual item in the class?
public class Person { private string Name; private string Address; }
a function in my files class would be something like this abreviation
public void Personrecord(Pe rson)
INSERT INTO Personrecord (" + "Name , Address "+") VALUES (' "+Name + " ' , ' " + Address +" ' )";
how can I pass a person instead of each variable, Name and Address?
It is hard for a nube since I am not sure "Exactly" how to ask this.
thank you for any and all help
Jerry
On Sat, 20 Nov 2004 16:37:27 -0500, "Thomas P. Skinner [MVP]" <to*@bu.edu> wrote:
well I guess this is where I am confused.
yes I can use accessors to get each value but I was wondering if I could pass Person
instead of each individual item that makes up a person from my person.cs
this is what I have in my files.cs file
public void fileSaver(strin g Name,string Address)
{
string sCommand = " INSERT INTO tblPerson(Name, Address)" +
"VALUES (" + Name + ",'" + Address + ")";
Connection.Open ();
OleDbCommand cmd = new OleDbCommand (sCommand, Connection);
command.Execute NonQuery();
Connection.Clos e();
I was wondering if I could pass a person
public void filesaver(Perso n)
=============== =======
does this make since?
ps the command has me confused as well..
this does not work...am I doing something wrong? yes I am sure I am since it doesn't work
even though this is an example in the dietel book, which I am using.
Yes, you can.
Person is the type, person is the instance
public void fileSaver(Perso n person)
....
string sCommand = " INSERT INTO tblPerson(Name, Address)" +
"VALUES (" + person.Name + ",'" + person.Address + ")";
....
Please look into using parameterized SQL and/or stored procs to prevent sql
injection attacks.
"sparks" <jo***@lost.net > wrote in message
news:fe******** *************** *********@4ax.c om... On Sat, 20 Nov 2004 16:37:27 -0500, "Thomas P. Skinner [MVP]" <to*@bu.edu> wrote:
well I guess this is where I am confused. yes I can use accessors to get each value but I was wondering if I could pass Person instead of each individual item that makes up a person from my person.cs
this is what I have in my files.cs file
public void fileSaver(strin g Name,string Address) { string sCommand = " INSERT INTO tblPerson(Name, Address)" + "VALUES (" + Name + ",'" + Address + ")";
Connection.Open (); OleDbCommand cmd = new OleDbCommand (sCommand, Connection); command.Execute NonQuery(); Connection.Clos e();
I was wondering if I could pass a person
public void filesaver(Perso n) =============== =======
does this make since?
ps the command has me confused as well.. this does not work...am I doing something wrong? yes I am sure I am since it doesn't work even though this is an example in the dietel book, which I am using.
If you are asking if you can pass a person object in an SQL statement then I
believe the answer is no. If you are asking if you can pass a person object
to a function then this has been explained and you can.
Thomas P. Skinner [MVP]
"sparks" <jo***@lost.net > wrote in message
news:fe******** *************** *********@4ax.c om... On Sat, 20 Nov 2004 16:37:27 -0500, "Thomas P. Skinner [MVP]" <to*@bu.edu> wrote:
well I guess this is where I am confused. yes I can use accessors to get each value but I was wondering if I could pass Person instead of each individual item that makes up a person from my person.cs
this is what I have in my files.cs file
public void fileSaver(strin g Name,string Address) { string sCommand = " INSERT INTO tblPerson(Name, Address)" + "VALUES (" + Name + ",'" + Address + ")";
Connection.Open (); OleDbCommand cmd = new OleDbCommand (sCommand, Connection); command.Execute NonQuery(); Connection.Clos e();
I was wondering if I could pass a person
public void filesaver(Perso n) =============== =======
does this make since?
ps the command has me confused as well.. this does not work...am I doing something wrong? yes I am sure I am since it doesn't work even though this is an example in the dietel book, which I am using.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rex_chaos |
last post by:
Hi all,
I am writing a project in C++. I am going to compile all my source
to a library(.a). So I can only distribute the lib as well as the
header file to my client. However, I don't quite familiar with C++
programming. In my project, I have defined a heap of classes, the
definition of which defined in a hearder file. On the other hand, I
would like to limit all the classes in a namespace.
Can anyone please tell me how to write the...
|
by: Micha |
last post by:
Hello there,
I think I've run into some classic c++ pitfall and maybe some of
you guys can help me out.
For my project I will need to use matrices and vectors and so I
decided to implement them by myself. I know there are already
tons of vector and matrix implementations, but I wanted to have
one taylored for my needs and without debugging someones
else code. Also is's become somewhat personal meanwhile ;-).
|
by: Noel |
last post by:
Hello,
I'm currently developing a web service that retrieves data from an employee
table. I would like to send and retrieve a custom employee class to/from the
webservice. I have currently coded the custom employee class and have built
it as a separate library (employee.dll). This employee.dll is being
referenced by both the web service and the windows application.
I face the following problem when I send this class to the webservice.
|
by: Miguel Guedes |
last post by:
Hello,
I recently read an interview with Bjarne Stroustrup in which he says
that pure abstract classes should *not* contain any data. However, I
have found that at times situations are when it would be useful to have
/some/ data defined in such an abstract class for reasons of forming a
common block of data existing in or used by all descendant classes (see
example below.) In such a case where a common block of data *always*
exists,...
|
by: CuTe_Engineer |
last post by:
hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes
#these are the operations
+ = ,
- = ,
* = ,
1/ = only if 0 not in .
| |
by: raylopez99 |
last post by:
Keywords: scope resolution, passing classes between parent and child
forms, parameter constructor method, normal constructor, default
constructor, forward reference, sharing classes between forms.
Here is a newbie mistake that I found myself doing (as a newbie), and
that even a master programmer, the guru of this forum, Jon Skeet,
missed! (He knows this I'm sure, but just didn't think this was my
problem; LOL, I am needling him)
If...
|
by: shapper |
last post by:
Hello,
Lately I have been working with ASP.NET MVC and C#.
I have been building a lot of code and I am struggling to find a good
way to organize it.
I am posting some of the code I have been building:
HTML Helpers
|
by: K Viltersten |
last post by:
I have a solution with a project names
ProjA and ProjB. In ProjA i have a class
called ClassA. It contains a static,
public member MembA.
I'd like to read MembA when executing
code in class ClassB in the project
ProjB, but when i try the following, i
get nothing from Intellisense (and it
doesn't compile either).
|
by: Cralis |
last post by:
Hi guys,
Someone once said, 'You can do that with reflection'. I can't recall
what it was I was trying to do at the time, but then he said, 'Any
developer knows what reflection is...'. I kept quiet and smiled.
What is reflection!?
I have been reading it up, and all I can work out is that it has
something to do with Late Binding, and the use of GetType and Type.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |