Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Comments
OriginalGriff 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 24-Nov-12 10:42am    
i have told in the most appropriate way...its your problem that you are unable to understand
OriginalGriff 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 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 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......

1 solution

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



VB
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900