简体   繁体   English

我已将表格字段和文本框值存储在两个不同的列表中 <string> 现在我想在插入查询中使用那些列表怎么做?

[英]I have stored Table fields and Textbox values in two different list<string> now I want to use those lists in insert query how to do it?

I have stored Table fields and Textbox values in two different list<string> . 我已经将Table字段和Textbox值存储在两个不同的list<string>

I want to use those lists in insert query how to do it ? 我想在插入查询中使用这些列表怎么做? and what about quotation marks if value is numeric ? 如果值是数字,引号又如何呢?

foreach (Control Txt_Name in TB_List) {
  String TxtName = Txt_Name.Text;
  String field_name = Txt_Name.Name.Substring(3);
  Field_Name.Add(field_name);
  TB_Name.Add(TxtName);
}
SqlCommand cmd = new SqlCommand("Insert into "+ Table_Name +
  "('"+ Field_Name + "') Values('" + TB_Name + "')", con); 

Table field must be separated with commas. 表字段必须用逗号分隔。 Value field must be treated in different ways. 值字段必须以不同的方式处理。 Example: String values want the single quote before and after the value, int doesn't.. The best way is to handle the insert statement with a sql procedure. 示例:字符串值希望在值的前后使用单引号,而int则不希望。最好的方法是使用sql过程来处理insert语句。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在一个查询中从两个不同的表中的一个位置制作数据,我必须使用数据透视表 - I want to make the data at one place from two different table in one query i have to make the use of pivot 如何编写两个不同表的文本框和datagridview值的插入查询? - How to write insert query for textbox and datagridview values for two different tables? 我有两个字符串列表,如何从每个列表索引中创建一个字符串? - I have two Lists of string how can i create a string from each List index with the other one? 如何连续两个random给出不同的值? - How do I have two randoms in a row give different values? 我已经将表单名称存储在数据库中。 现在我想使用这些名称加载表格 - I've stored form names in a data base. now i want to load forms by using those names C#我有清单 <object> 内部更改了对象值,现在我想删除 - C# i have List<object> with object values internally changed and now i want to remove 如果其值出现在列表中但不在表中,如何插入行;如果它们的值不在列表中但在表中,如何删除行? - How do I insert rows if their values appear in a list but are not in the table and delete them if they do not appear in the list but are in the table? 我可以使用LINQ查询两个列表以填充单个列表吗 - Can I use LINQ to query two Lists to populate a single List 如何将动态创建的文本框值插入数据库 - How Do I Insert Dynamically Created Textbox Values To Database 我已经在数据库中创建了存储过程,在我的 C# 代码中我想将插入查询转换为该存储过程 - I have stored procedure created in the database, in my C# code I want to convert the insert query into that stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM