添加记录 [英] ADD RECORDS

查看:40
本文介绍了添加记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ASP.net 1.1

2问题:

1.为什么我的写命令不起作用?

2.此文件成功在数据库记录中进行更改。

肯定是一些简单的代码我可以添加*将*记录添加到这个

数据库。谁可以告诉我?


<%@ Page Language =" VB"调试= QUOT;真" %>


<%@ Import Namespace =" System.Data.Oledb" %>


< script runat =" server">


受保护的子Page_Load(ByVal发件人作为对象,ByVal e As System.EventArgs)

Dim DBConnection OledbConnection


DBConnection =新的OledbConnection(Provider = Microsoft.Jet.Oledb.4.0;"& _


数据源= C:\Inetpub \ www.root \ app_data \Acc.mdb)

DBConnection.Open ()


Dim DBCommand为OledbCommand


DBCommand =新OledbCommand(SELECT * FROM table1,Acc)


昏暗的SQLString AS字符串


SQLString =" UPDATE Table1 SET TheEmpName ='''POOOOO''WHERE TheDate =''6/14/07''" ;


DBCommand =新的OleDBCommand(SQLString,DBConnection)


DBCommand.ExecuteNonquery()


Dim DBReader AS OledbDatareader


DBReader = DBCommand.ExecuteReader()


DBReader.Read()


Response.Write(DBReader(" TheDate"))

Response.Write(DBReader(" TheEmpName") ;))


结束时


''MyDataGrid.DataSource = DBReader


'' MyDataGrid.DataBind()


DBReader.Close()


DBConnection.Close()


结束子


< / script>


< / head>


< ; body>


< form id =" form1" runat =" server">


< asp:DataGrid id =" MyDataGrid" runat =" server" />


< / form>


< / body>

< / html>

解决方案

" dancer" < da **** @ microsoft.comwrote in message

news:uo ************* @ TK2MSFTNGP05.phx.gbl ...


使用ASP.net 1.1

2问题:

1.为什么我的写命令不起作用?

2.此文件成功更改了数据库记录。

肯定是一些简单的代码我可以添加*将*记录添加到这个

数据库。谁能告诉我?



好​​吧,首先如果你能够编辑现有记录,至少*一些*

你的写命令正在工作。 .. :-)


1)您实际使用什么代码将记录添加到数据库中?我看到一个

UPDATE SQL语句用于更新现有记录 - 在哪里是你的

相应的INSERT语句用于添加新记录......?


2)你从数据库中得到什么错误?

-

Mark Rae

ASP.NET MVP http://www.markrae.net


RE:1)您实际使用哪些代码将记录添加到数据库中?我是
看到


更新现有记录的更新SQL语句 - 你的

对应INSERT语句添加新记录......?



我没有使用任何代码来添加记录。这是我的问题:什么代码可以

我添加添加记录?


RE:2)你从数据库中得到什么错误?

无。

我的代码完全符合它的意图:根据

a标准更新记录。唯一不起作用的部分是这两行:


Response.Write(DBReader(" TheDate"))


响应。写(DBReader(" TheEmpName"))


这就是我所说的为什么不写?我想看看如果它是b $ b更新记录而不必查看数据库,因此我将b $ b包括在那些行中,但它们并没有写。所以我可以看到更新的

字段。


谢谢。


" Mark Rae [MVP ]" < ma ** @ markNOSPAMrae.netwrote in message

news:eL ************** @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
" dancer" < da **** @ microsoft.comwrote in message

news:uo ************* @ TK2MSFTNGP05.phx.gbl ...


>使用ASP.net 1.1
2问题:
1。为什么我的写命令不起作用?
2。此文件成功更改了数据库记录。肯定有一些我可以添加的简单代码*将*记录添加到此
数据库中。谁能告诉我?



好​​吧,首先如果你能够编辑现有记录,至少*一些*

你的写命令正在运行。 .. :-)


1)您实际使用什么代码将记录添加到数据库中?我看到

用于更新现有记录的UPDATE SQL语句 - 您的

对应的INSERT语句用于添加新记录...?


2)你从数据库中得到什么错误?


-

Mark Rae

ASP.NET MVP
http://www.markrae.net



"舞蹈家" < da **** @ microsoft.comwrote in message

news:em ************** @ TK2MSFTNGP04.phx.gbl ...


> RE:1)您实际使用哪些代码将记录添加到数据库?
我看到一个UPDATE SQL语句用于更新现有记录 -
用于添加新记录的相应INSERT语句...?



我没有使用任何代码来添加记录。这是我的问题:我可以添加什么代码

来添加记录?



哦对了...

将记录添加到Jet数据库中的表的SQL语法是:


INSERT INTO表(field1,Field2 ...)VALUES(Value1,Value2 ......)


RE:2你从数据库中得到什么错误?

无。

我的代码完全符合它的意图:根据
更新记录
符合标准。唯一不起作用的部分是这两行:


Response.Write(DBReader(" TheDate"))


响应。写(DBReader(" TheEmpName"))


这就是我所说的为什么不写?我想看看如果它是b $ b更新记录而不必查看数据库,因此我将b $ b包括在那些行中,但它们并没有写。这样我就可以看到

更新字段了。



您正在正确发布UPDATE语句,但是,如果您想看到

它已经有效,那么您将需要发出一个SELECT语句来获取你刚刚从数据库中更新的

记录...

-

Mark Rae

ASP.NET MVP
http://www.markrae。网


Using ASP.net 1.1
2 QUESTIONS:
1. Why do my write commands not work?
2. This file successfully makes changes in the database record. There
surely is some simple code I could add that would *add* records to this
database. Who can tell me?

<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="System.Data.Oledb" %>

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DBConnection As OledbConnection

DBConnection = New OledbConnection("Provider=Microsoft.Jet.Oledb.4.0; " & _

"Data Source=C:\Inetpub\wwwroot\app_data\Acc.mdb" )

DBConnection.Open()

Dim DBCommand As OledbCommand

DBCommand = New OledbCommand("SELECT * FROM table1, Acc")

Dim SQLString AS String

SQLString = "UPDATE Table1 SET TheEmpName=''POOOOO'' WHERE TheDate=''6/14/07''"

DBCommand = New OleDBCommand(SQLString, DBConnection)

DBCommand.ExecuteNonquery()

Dim DBReader AS OledbDatareader

DBReader = DBCommand.ExecuteReader()

While DBReader.Read()

Response.Write(DBReader("TheDate"))

Response.Write(DBReader("TheEmpName"))

End while

'' MyDataGrid.DataSource = DBReader

''MyDataGrid.DataBind()

DBReader.Close()

DBConnection.Close()

End Sub

</script>

</head>

<body>

<form id="form1" runat="server">

<asp:DataGrid id="MyDataGrid" runat="server"/>

</form>

</body>

</html>

解决方案

"dancer" <da****@microsoft.comwrote in message
news:uo*************@TK2MSFTNGP05.phx.gbl...

Using ASP.net 1.1
2 QUESTIONS:
1. Why do my write commands not work?
2. This file successfully makes changes in the database record. There
surely is some simple code I could add that would *add* records to this
database. Who can tell me?

Well, firstly if you''re able to edit existing records, at least *some* of
your write commands are working... :-)

1) What code are you actually using to add records to the database? I see an
UPDATE SQL statement for updating existing records - where is your
corresponding INSERT statement for adding new records...?

2) What errors are you getting back from your database?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


RE:1) What code are you actually using to add records to the database? I
see an

UPDATE SQL statement for updating existing records - where is your
corresponding INSERT statement for adding new records...?

I am not using any code to add records. That was my question: What code can
I add to add records?

RE: 2) What errors are you getting back from your database?
None.
My code does exactly what it''s intended to do: updates a record according to
a criteria. The only part that does not work are these two lines:

Response.Write(DBReader("TheDate"))

Response.Write(DBReader("TheEmpName"))

That''s what I meant by "why does it not write?" I wanted to SEE if it
updates the record without having to look at the database, therefore I
included those lines, but they do not "write" so that I can see the updated
field.

Thank you.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:eL**************@TK2MSFTNGP05.phx.gbl...

"dancer" <da****@microsoft.comwrote in message
news:uo*************@TK2MSFTNGP05.phx.gbl...

>Using ASP.net 1.1
2 QUESTIONS:
1. Why do my write commands not work?
2. This file successfully makes changes in the database record. There
surely is some simple code I could add that would *add* records to this
database. Who can tell me?


Well, firstly if you''re able to edit existing records, at least *some* of
your write commands are working... :-)

1) What code are you actually using to add records to the database? I see
an UPDATE SQL statement for updating existing records - where is your
corresponding INSERT statement for adding new records...?

2) What errors are you getting back from your database?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net



"dancer" <da****@microsoft.comwrote in message
news:em**************@TK2MSFTNGP04.phx.gbl...

>RE:1) What code are you actually using to add records to the database?
I see an UPDATE SQL statement for updating existing records - where is
your corresponding INSERT statement for adding new records...?

I am not using any code to add records. That was my question: What code
can I add to add records?

Oh right...

The SQL syntax to add a record into a table in a Jet database is:

INSERT INTO Table (field1, Field2...) VALUES (Value1, Value2...)

RE: 2) What errors are you getting back from your database?
None.
My code does exactly what it''s intended to do: updates a record according
to a criterion. The only part that does not work are these two lines:

Response.Write(DBReader("TheDate"))

Response.Write(DBReader("TheEmpName"))

That''s what I meant by "why does it not write?" I wanted to SEE if it
updates the record without having to look at the database, therefore I
included those lines, but they do not "write" so that I can see the
updated field.

You''re issuing your UPDATE statement correctly but, if you want to see that
it has worked, you will then need to issue a SELECT statement to fetch the
record you''ve just updated back out of the database...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


这篇关于添加记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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