简体   繁体   English

如何在ASP.Net网页上使用OleDb向数据库添加新行

[英]How to add new row to database with OleDb on a ASP.Net webpage

The problem: 问题:

I have a webpage with 18 text box fields that I need to insert into a row. 我有一个包含18个文本框字段的网页,需要将其插入一行。 The column names are kept inside a Label array called labelArray . 列名保存在名为labelArray的Label数组labelArray The text fields that the user enters data in will be in a Textbox array called textArray.Text . 用户输入数据的文本字段将在一个名为textArray.Text的Textbox数组中。

I want to know how I can pass all 18 of my text fields in textArray to my Data Access Layer where I make my insert these fields into the database. 我想知道如何将textArray所有18个文本字段textArray到我的数据访问层,在其中我将这些字段插入数据库。 My problem right now is that I cannot pass and array over to a class file. 我现在的问题是我无法将数组传递给类文件。 Is it possible to covert to string and pass over the insert string to my Data Access Layer? 是否可以隐式转换为字符串并将插入字符串传递给我的数据访问层?

The problem in more depth: 问题更深入:

There is two columns with data that are set to Date/Time in my MS access database. 我的MS Access数据库中有两列数据设置为“日期/时间”。 How can I pass through a Date Time object to my access table? 如何将日期时间对象传递到访问表? Is it ok if it's a formated string? 如果它是格式化的字符串,可以吗?

If you need to see some code I have, I'm ready to post them and will be on StackOverflow for the next few hours. 如果您需要查看我拥有的一些代码,我准备将其发布,并将在接下来的几个小时内出现在StackOverflow上。

The following code will convert a Textbox[] into an equivalent string representation: 以下代码会将Textbox[]转换为等效的字符串表示形式:

var str = String.Join("\",\"", TextArray.Select(tb => tb.Text));
if (!string.IsNullOrEmpty(str)) {
    str = "\"" + str + "\"";
}
str = "[" + str + "]";

Keep in mind that double-quotation marks will not be escaped. 请记住,双引号不会被转义。 Solutions can be found here and here . 解决方案可以在这里这里找到。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM