插入记录的通用函数

插入记录的通用函数

本文介绍了插入记录的通用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这是迪纳卡.我正在输入xml,其中包含表名,列名,类型和值.我希望通用函数通过使用上述xml表值来插入一条记录.
请帮帮我.....


This is dinakar. I am having input xml, which contain table name,column name ,type and values. I want generic function to insert a record by using above xml table values.
please help me out please.....

推荐答案


  1. 从XML中提取表名和列名,值和类型.实现此目标的一种方法是使用XPath表达式.
  2. 根据在步骤1中检索到的数据构造插入语句.

  1. Extract the table name and column name(s), value(s) and type(s) from your XML. One way to achieve that would be the use of XPath expressions.
  2. Construct insert statements from the data retrieved in step 1.:
String myStringSQLStatement = String.Format("INSERT INTO {0} {1} VALUES({3})", tableName, columnList, paramNameList);


其中,tableName是XML中的表名,而columnList是用逗号分隔的列名列表.对于paramNameList,请使用以@开头的列名,并以逗号分隔.

  • 接下来建立与数据库的连接,使用生成的字符串创建一个SQL语句.
  • 接下来,向您的语句中添加SqlParameters,同时使用从XML中获取的适当类型.
  • 运行SqlStatement并获取结果.

  • where tableName is the table name from the XML and the columnList is the list of the column names seperated by a comma. For the paramNameList use the column names prefixed by a @ and also separate them by a comma.

  • Next make a connection to your DB, create a SQL statement form the string you generated.
  • Next add SqlParameters to you statement with the appropriate type which you also fetched from your XML.
  • Run your SqlStatement and fetch the results.


  • 遵循此路线,使您的问题与进度保持最新,并告诉我们在解决此问题时是否遇到任何问题.

    最好的问候,

    --MRB



    Follow this route, keep your question updated with your progress and tell us if you run across any problems while you''re working this out.

    Best Regards,

    --MRB


    这篇关于插入记录的通用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-19 09:36