插入查询的代码 [英] code for the insert query
问题描述
我想为插入查询编写代码
在这我是我的默认页面,我必须使用名称valuecollection,在我的班级中,我将有一个带有两个参数的方法(字符串表名称,名称值集合),并且在该方法中,我的插入查询应非常强大,以至于我不应该更改表名称更改中或添加了新列..
其次,名称valucollection应该具有键作为列名,并将vaue插入作为键值...
仅将此namevalue clooection和tabename传递给class方法,并应在该方法中触发insert查询,以便插入记录
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
推荐答案
Hello Aqueel,
所以据我了解...
您要创建一个类,
在您的课程中,您将有一个带有两个参数的方法
TableName作为字符串和NameValue对的集合
在您的类中还将有一种方法,用于将NameValue集合中的数据插入到TableName
中命名的表中 而且您的VALIDATION应该足够强大,以至于不能以任何方式更改数据
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
这篇关于插入查询的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!