将完整数据集转换为空SQL表 [英] Full dataset into an empty SQL table

查看:56
本文介绍了将完整数据集转换为空SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我设法创建了一个SQL服务器数据库和一个表。这张桌子是空的,这让我有了下一个挑战:


我怎样才能获得数据集中表格中的信息SQL

表?


是否有一种简短的方法,比如FILL方法将数据输入数据集或执行

我有阅读表中的每个数据行并将其写入

数据库?


rg,

Eric

Hi,

I managed to create a SQL server database and a table in it. The table is
empty and that brings me to my next chalenge:

How can I get the info in the table in the dataset to go in an empty SQL
table?

Is there a short way like the FILL method to get data into the dataset or do
I have to read each datarow in the table and write it one at the time to the
database?

rg,
Eric

推荐答案

你好EMW,


与填充相反的是更新。

(别忘了看看'commandbuilder',否则你有很多工作要做的工作)。


我希望这有帮助吗?


Cor
Hi EMW,

The opposite from the Fill is the Update.
(And don''t forget to look at "commandbuilder", otherwise you have a lot of
work to do).

I hope this helps?

Cor

我设法在其中创建一个SQL服务器数据库和一个表。该表是空的,这将我带到我的下一个chalenge:
如何获取数据集中的表中的信息以进入一个空的SQL
表?
是有一个简短的方法,如FILL方法将数据输入数据集或
我是否必须读取表中的每个数据行并将其写入数据库中的

I managed to create a SQL server database and a table in it. The table is
empty and that brings me to my next chalenge:
How can I get the info in the table in the dataset to go in an empty SQL
table?
Is there a short way like the FILL method to get data into the dataset or do I have to read each datarow in the table and write it one at the time to the database?



我正在尝试使用更新,但在我看来,我正在更新

数据集(因此丢失了信息)。


" Cor" < no*@non.com> schreef in bericht

新闻:O0 ************** @ TK2MSFTNGP10.phx.gbl ...
I''m currently trying things with update, but it seems to me I''m updating the
dataset (thus losing the info).

"Cor" <no*@non.com> schreef in bericht
news:O0**************@TK2MSFTNGP10.phx.gbl...
嗨EMW,(不要忘记查看commandbuilder,否则你有很多工作要做)。

我希望这有帮助吗?

Hi EMW,

The opposite from the Fill is the Update.
(And don''t forget to look at "commandbuilder", otherwise you have a lot of
work to do).

I hope this helps?

Cor

我设法在其中创建一个SQL服务器数据库和一个表。表
是空的,这将我带到我的下一个挑战:
如何获取数据集中表格中的信息以进入一个空的SQL
表?
是有一种简短的方法,如FILL方法将数据输入数据集

I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge:
How can I get the info in the table in the dataset to go in an empty SQL
table?
Is there a short way like the FILL method to get data into the dataset


或做

我必须读取表中的每个数据行并将其写入
I have to read each datarow in the table and write it one at the time to


数据库?






此时更新命令对你没有好处。你需要先使用添加功能将数据添加到你的表格

才能更新它。


下面是一个代码片段显示您必须首先使用

有效的SQL Select语句,打开您的记录集然后再添加到它b
。不要忘记申报你的记录集

或者你会遇到问题。


这是添加新事件的添加按钮事件的代码

用户到桌子。


SQL =" SELECT * FROM tusers WHERE UserID =''" &安培;修剪

(txtFName.Text)&修剪(txtLName.Text).Substring(0,1)

& "''"

Rs.Open(SQL,Your_Connection.RETURN_CONNECTION,

ADODB.CursorTypeEnum.adOpenDynamic,

ADODB.LockTypeEnum。 adLockBatchOptimistic)

如果Rs.EOF那么

Rs.AddNew()

调用SetDataUser()

卢比。 UpdateBatch()

MsgBox(已添加记录。)

否则

MsgBox(UserID已被采用。请

通过更改用户的名字来创建一个新的。

这将有助于为该人创建一个唯一的ID。)

Rs.Close()

退出Sub

结束如果

Rs.Close()

总是关闭使用它后你的记录集确保

所有更新都会发生,你不会意外地崩溃你的

程序。


电话SetDataUser()调用一个子程序,将每个字段分配给表中相应的一个字段,如下面的



Private Sub SetDataUser ()


Dim myString As String = txtLName.Text

Dim myChar作为Char

myChar = myString.Chars(0)


Rs.Fields(0).Value = txtFName.Text& myChar

Rs.Fields(1).Value = txtLName.Text

Rs.Fields(2).Value = txtFName.Text

Rs .Fields(4).Value = cmboBoxDept.SelectedItem

如果cmboboxbackup.SelectedItem =""然后

Rs.Fields(5).Value =" No back-up"

Else

Rs.Fields(5).Value =

cmboboxbackup.SelectedItem

结束如果


结束子


希望这个帮助

The update command will do you no good at this point. You
must use the Add function first to add data to your form
before you can update it.

Below is a snippet of code that shows you must have a
valid SQL Select statement first, open your recordset and
then add to it. Do not forget to declare your recordset
or you will have problems.

This is the code for an add button event to add a new
user to a table.

SQL = "SELECT * FROM tusers WHERE UserID = ''" & Trim
(txtFName.Text) & Trim(txtLName.Text).Substring(0, 1)
& "''"
Rs.Open(SQL, Your_Connection.RETURN_CONNECTION,
ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockBatchOptimistic)
If Rs.EOF Then
Rs.AddNew()
Call SetDataUser()
Rs.UpdateBatch()
MsgBox("Record has been added.")
Else
MsgBox("UserID has already been taken. Please
create a new one by changing the first name of the user.
This will help create a unique ID for that person.")
Rs.Close()
Exit Sub
End If
Rs.Close()
Always close your recordset after using it to make sure
all updates occur and you do not accidentally crash your
program.

The Call SetDataUser() calls a subroutine that assigns
each field to it''s corresponding one in the table like
below:
Private Sub SetDataUser()

Dim myString As String = txtLName.Text
Dim myChar As Char
myChar = myString.Chars(0)

Rs.Fields(0).Value = txtFName.Text & myChar
Rs.Fields(1).Value = txtLName.Text
Rs.Fields(2).Value = txtFName.Text
Rs.Fields(4).Value = cmboBoxDept.SelectedItem
If cmboboxbackup.SelectedItem = "" Then
Rs.Fields(5).Value = "No back-up"
Else
Rs.Fields(5).Value =
cmboboxbackup.SelectedItem
End If

End Sub

Hope this helps
-----原始消息-----
我正在尝试更新的东西,但它似乎是我b $ b我更新数据集(因此丢失信息)。

Cor < no*@non.com> schreef in bericht
新闻:O0 ************** @ TK2MSFTNGP10.phx.gbl ...
-----Original Message-----
I''m currently trying things with update, but it seems to me I''m updating thedataset (thus losing the info).

"Cor" <no*@non.com> schreef in bericht
news:O0**************@TK2MSFTNGP10.phx.gbl...
嗨EMW,
(并且不要忘记查看commandbuilder,
否则你有很多
Hi EMW,

The opposite from the Fill is the Update.
(And don''t forget to look at "commandbuilder", otherwise you have a lot of
工作要做。)

我希望这有帮助吗?

work to do).

I hope this helps?

Cor
>
>我设法在其中创建一个SQL服务器数据库和一个
表。表
>
> I managed to create a SQL server database and a table in it. The table
是>空的,这让我进入下一个挑战:
>如何获取数据集
is > empty and that brings me to my next chalenge:
> How can I get the info in the table in the dataset


中表格中的信息以进入空SQL>桌子?
>有没有像FILL方法那样的简短方法将

to go in an empty SQL > table?
> Is there a short way like the FILL method to get


数据输入数据库

data into the datasetor

do
>我必须阅读表格中的每个数据行,然后将
> I have to read each datarow in the table and write



写入


it one at the time to the

>数据库?





.



这篇关于将完整数据集转换为空SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆