Please help me out -
My Scenario -
I have total 3 class files -
1. AnnTblProperties
public class Announcements
{
public String Announcement
{
get;
set;
}
public DateTime CreatedDate
{
get;
set;
}
}
2. NewsTblProperties
public class News
{
public String News
{
get;
set;
}
public DateTime CreatedDate
{
get;
set;
}
}
3. InsertMethods
public class INsert{
public Datatable InsertValues (int Table, Announcement ann, News news)
{
if(table ==1 )
{
Insert in Announcement(Announcement, CreatedDate) values (ann.Announcement, ann.CreatedDate);
}
if(table ==2 )
{
Insert in News(News, CreatedDate) values (news.News, news.CreatedDate);
}
}
}
---
Table structure of Announcements and News are same - (In Annpuncement table, Column "News" is "Announcement").
| ID(PK, not Null) | News | CreatedDate |
| 1 | Item-1 | 3-Jan-2015 |
| 2 | Item-2 | 16-Jan-2015 |
| 3 | Item-3 | 4-Feb-2015 |
Say, if user selects "Announcements" from dropdownlist, then following steps takes place -
1. The below method is called (Validations done)
public Announcement SetValuesAnnouncement()
{
Announcements ann = new Announcements(); // object of class Announcements
ann.Announcement = txt_ann.text.trim();
ann.CreatedDate = System.datetime.now;
return ann;
}
Insert insrt = new Insert();
insrt(1,ann,null);
------------
Now,
The tables will be increased in future (structure will be same).
My query -
How do I pass just 2 values to the method InsertValues() ??
How do I pass many objects of classes in a single variable ??
My intend is to reduce the number of parameters.
Can we use collections like arrays or is there some other ways??
PLease Help !!
------
VulpesPosted Mar 21, 2015, 6:20 PM
dynamic objs = new dynamic[10]; // say
but I don't know what you're trying to achieve that you can't achieve with params object[]?
Riddhi ValechaPosted Mar 21, 2015, 7:12 AM
Can I use "dynamic" keyword here ??
Is the following possible -
dynamic objs = new dynamic[];
Or something else ??
VulpesPosted Mar 19, 2015, 9:33 AM
You could also use a parameter object array i.e. declare the method as:
This wouldn't affect the code in the body of the method as parameter arrays are processed in exactly the same way as ordinary arrays.
Riddhi ValechaPosted Mar 19, 2015, 8:00 AM
I mentioned earlier also... Now, I have to perform this same thing in 12 tables in sql server.
The operations are -
1. Select.
2. Insert.
3. Update.
4. Search.
----
Please guide... Which one should I use -
Object[],
List[],
---
or any other...
I just want to reduce the number of parameters in the method.
Eg-
public datatable Insert(int i, class ann, class news, class events)
{
cmd.Parameters.AddWithValues("@ID",i);
}
--
In Stored Procedure -
If I pass value 1, and "Select" Method,
VulpesPosted Feb 22, 2015, 9:42 AM
Riddhi ValechaPosted Feb 22, 2015, 5:06 AM
I am trying your way out...
But, I want to ask 1 query... Is there a way in which I can send 2 parameters ??
E.G - Insert (int i, Arraylist[3]) or something like this ??
Can I use any collections ( Arrays, Lists, Dictionary, etc) for class objects ?? If yes, then how ???
VulpesPosted Feb 21, 2015, 7:33 AM