Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET ADO.NET
i want to write a code for an insert query
in this i my default page i have to use name valuecollection and in my class i will have a method with two parameter (string table name,name value collection) and in the method my insert query should be so strong that i should not be change in table name change or new cols are added..
secondaly name valucollection should have key as column name and vaue to be inserted as key value...
only this namevalue clooection and tabename should be passed to the class method and in the method the insert query should should be fired so that records are inserted
Posted 23-Nov-12 23:30pm
Comments
OriginalGriff at 24-Nov-12 5:39am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Aqueel Ahmad at 24-Nov-12 10:42am
   
i have told in the most appropriate way...its your problem that you are unable to understand
OriginalGriff at 24-Nov-12 11:05am
   
"its your problem that you are unable to understand"
 
Not really.
 
I'm not the one waiting for an answer...
Nelek at 24-Nov-12 14:08pm
   
If you think that's the most appropiate mode... then I don't want to ask what you consider the worst.
 
Just for your info: You are not having any punctuation signs (they help to understand the text), you have spelling errors, the gramatic is so bad than even me (non english speaker) see the errors.
 
And just to end... being rude with the best option you have to get an answer, that wasn't the best idea.
Aqueel Ahmad at 25-Nov-12 2:02am
   
you are here to check spellings and English grammar or to resolve the problem... and i don't think so that you are not able to understand my problem... any how that's your problem.. if you can help me it will be my pleasure and if you are not able to help then also you are welcome......
Nelek at 25-Nov-12 5:46am
   
No, I am not here to check spelling or grammar. And I don't care at all on how you write. But I DO care if I see an answer like yours to one of the most respected users in CP that help A LOT people like you for free, so the less you can do is to show a bit respect to the people helping.
 
If you say "I have told in the most appropiate way", then I will tell you... "no, you haven't, because of..." (as I did).
 
I just wanted to explain you the reason of my comment. If you understand it and learn from this situation... better for you. If not... I think you are going to do the things on your own, because with that attitude few people will be helping you.
HabeshaMan at 26-Nov-12 17:42pm
   
Post sample code that could make it easy to understand.and please be respectful.
Paw Jershauge at 24-Nov-12 17:03pm
   
Is it an codegenerator your lookin for or ???

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello Aqueel,
 
So as i understand it...
 
You want to create a class,
and in your class you will have a method with two parameter
TableName as String and Collection of NameValue pairs
 
Also in your class will be a method to insert the data in the NameValue collection into the table named in TableName
And your VALIDATION should be so strong that the data cannot be changed in any way
 

 
Class MyClass
 
    Function InsertThisData(ByVal strTableName As String, ByVal colNVP As System.Collections.Specialized.NameValueCollection) As Boolean
 
        InsertThisData = False
        'check tablename is okay
        If Trim(strTableName) <> "" Then
            If (colNVP Is Nothing = False) Then
                '
                '  VALIDATE THE DATA IS ALL CORRECT HERE
                '  
                If colNVP.Count > 0 Then
                    '1  build SQL INSERT query
                    '2  open connection using your connectionstring
                    '3      TRY
                    '4          Insert data into table
                    '5          InsertThisData = TRUE
                    '5      CATCH
                    '6          error - error whilst saving data
                    '7      END TRY
                    '4 - close connection
                Else
                    'Error - collection is empty
                End If
            Else
                'Error - collection is nothing/null
            End If
        Else
            'Error - TableName is missing
        End If
 
    End Function
 

End Class
 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 241
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web04 | 2.8.140902.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100