如何将记录集值插入表中?

时间:2021-10-18 01:57:18

How to insert record set value

如何插入记录集值

Am having 6 fields in the record set

我在记录集中有6个字段

I want to insert into the table? How can I insert.

我想插入表格?我怎么插入

Used Query

INSERT INTO table values (recordset (0), recordset (1) ….. recordset (6)) 

But It showing Undefined function “recordset”

但它显示未定义的功能“记录集”

Please how to insert record set value in to the table?

请问如何将记录集值插入表中?

Query Help?

5 个解决方案

#1


Dim cmdCommand As New ADODB.Command
If recordSet.EOF = False Then

recordSet.MoveFirst

cmdCommand.CommandText = "insert into table ( field1) values ( " + recordSet.Fields(0) + ")"
cmdCommand.Execute()
recordSet.MoveNext
Loop Until recordSet.EOF = True

Keep in mind that you will need quotes in varchar fields

请记住,varchar字段中需要引号

#2


Try with the recordsetname.fields("field_name") and check that the recorsetname variable was defined. You can also use the syntax recordsetname!field_name.

尝试使用recordsetname.fields(“field_name”)并检查是否已定义recorsetname变量。您还可以使用语法recordsetname!field_name。

#3


Konstantinos gives a good answer, but you just need to be careful of the potential for SQL Injection issues.

Konstantinos给出了一个很好的答案,但您只需要注意SQL注入问题的可能性。

The simplest fix would be to just replace any single apostrophes with two.

最简单的解决方法是用两个替换任何单个撇号。

.CommandText = "insert into table (field1) values ( '" & Replace(recordSet.Fields(0), "'", "''") & "')"

.CommandText =“插入表(field1)值('”和替换(recordSet.Fields(0),“'”,“''”)和“')”

#4


It sounds like you're attempting to INSERT multiple records using a single statement (one INSERT for 6 records instead of 6 INSERT for 1 record each). If that's the case, the INSERT syntax fully supports it.

听起来你正在尝试使用单个语句插入多个记录(一个INSERT用于6个记录而不是6个INSERT用于每个记录1个)。如果是这种情况,INSERT语法完全支持它。

Here's an example:

这是一个例子:

INSERT INTO MyTable
    (row1, row2)
SELECT 
    value1, value2
FROM
    OtherTable

When you look at it like this, you can basically take any SELECT statement and put the INSERT clause on top of it. Of course, the column names need to line up correctly for it to work.

当你这样看时,你基本上可以接受任何SELECT语句并将INSERT子句放在它上面。当然,列名称需要正确排列才能正常工作。

#5


You may insert data into database using the codeigniter Framework.

您可以使用codeigniter Framework将数据插入数据库。

Database

Table Name : user

表名:用户

Fields Name : name , email

字段名称:名称,电子邮件


Insert a record using codeigniter:

使用codeigniter插入记录:

//storing data **record** into an **Array**

$data(
      'name' => 'Rudra',
      'email' => 'rud.test@gmail.com',
)

//Inserting Array into Database Table Name : **user**

$this->db->insert('user',$data);

#1


Dim cmdCommand As New ADODB.Command
If recordSet.EOF = False Then

recordSet.MoveFirst

cmdCommand.CommandText = "insert into table ( field1) values ( " + recordSet.Fields(0) + ")"
cmdCommand.Execute()
recordSet.MoveNext
Loop Until recordSet.EOF = True

Keep in mind that you will need quotes in varchar fields

请记住,varchar字段中需要引号

#2


Try with the recordsetname.fields("field_name") and check that the recorsetname variable was defined. You can also use the syntax recordsetname!field_name.

尝试使用recordsetname.fields(“field_name”)并检查是否已定义recorsetname变量。您还可以使用语法recordsetname!field_name。

#3


Konstantinos gives a good answer, but you just need to be careful of the potential for SQL Injection issues.

Konstantinos给出了一个很好的答案,但您只需要注意SQL注入问题的可能性。

The simplest fix would be to just replace any single apostrophes with two.

最简单的解决方法是用两个替换任何单个撇号。

.CommandText = "insert into table (field1) values ( '" & Replace(recordSet.Fields(0), "'", "''") & "')"

.CommandText =“插入表(field1)值('”和替换(recordSet.Fields(0),“'”,“''”)和“')”

#4


It sounds like you're attempting to INSERT multiple records using a single statement (one INSERT for 6 records instead of 6 INSERT for 1 record each). If that's the case, the INSERT syntax fully supports it.

听起来你正在尝试使用单个语句插入多个记录(一个INSERT用于6个记录而不是6个INSERT用于每个记录1个)。如果是这种情况,INSERT语法完全支持它。

Here's an example:

这是一个例子:

INSERT INTO MyTable
    (row1, row2)
SELECT 
    value1, value2
FROM
    OtherTable

When you look at it like this, you can basically take any SELECT statement and put the INSERT clause on top of it. Of course, the column names need to line up correctly for it to work.

当你这样看时,你基本上可以接受任何SELECT语句并将INSERT子句放在它上面。当然,列名称需要正确排列才能正常工作。

#5


You may insert data into database using the codeigniter Framework.

您可以使用codeigniter Framework将数据插入数据库。

Database

Table Name : user

表名:用户

Fields Name : name , email

字段名称:名称,电子邮件


Insert a record using codeigniter:

使用codeigniter插入记录:

//storing data **record** into an **Array**

$data(
      'name' => 'Rudra',
      'email' => 'rud.test@gmail.com',
)

//Inserting Array into Database Table Name : **user**

$this->db->insert('user',$data);