473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADD RECORDS

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="Syst em.Data.Oledb" %>

<script runat="server">

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

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

"Data Source=C:\Inetp ub\wwwroot\app_ data\Acc.mdb" )

DBConnection.Op en()

Dim DBCommand As OledbCommand

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

Dim SQLString AS String

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

DBCommand = New OleDBCommand(SQ LString, DBConnection)

DBCommand.Execu teNonquery()

Dim DBReader AS OledbDatareader

DBReader = DBCommand.Execu teReader()

While DBReader.Read()

Response.Write( DBReader("TheDa te"))

Response.Write( DBReader("TheEm pName"))

End while

' MyDataGrid.Data Source = DBReader

'MyDataGrid.Dat aBind()

DBReader.Close( )

DBConnection.Cl ose()

End Sub

</script>

</head>

<body>

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

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

</form>

</body>

</html>
Jul 13 '07 #1
14 1612
"dancer" <da****@microso ft.comwrote in message
news:uo******** *****@TK2MSFTNG P05.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

Jul 14 '07 #2
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("TheDa te"))

Response.Write( DBReader("TheEm pName"))

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**@markNOSPA Mrae.netwrote in message
news:eL******** ******@TK2MSFTN GP05.phx.gbl...
"dancer" <da****@microso ft.comwrote in message
news:uo******** *****@TK2MSFTNG P05.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

Jul 16 '07 #3
"dancer" <da****@microso ft.comwrote in message
news:em******** ******@TK2MSFTN GP04.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("TheDa te"))

Response.Write( DBReader("TheEm pName"))

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

Jul 16 '07 #4
Thank you for helping me, Mark.

The INSERT INTO code works great as long as I'm inserting literals. For
example,
SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES(""Somebod y"", ""10/10/98"", ""10/11/98"")"

But I need to insert variables received form an input form. When I put the
variable names in place of the literals like this:
SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES(EmpName, DateOfAccident, NotifyDate)"
I get this error message:
No value given for one or more required parameters

What is the syntax for using variables as the values?


"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:es******** *****@TK2MSFTNG P04.phx.gbl...
"dancer" <da****@microso ft.comwrote in message
news:em******** ******@TK2MSFTN GP04.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("TheD ate"))

Response.Write (DBReader("TheE mpName"))

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

Jul 17 '07 #5
"dancer" <da****@microso ft.comwrote in message
news:eC******** ******@TK2MSFTN GP02.phx.gbl...
Thank you for helping me, Mark.

The INSERT INTO code works great as long as I'm inserting literals. For
example,
SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES(""Somebod y"", ""10/10/98"", ""10/11/98"")"

But I need to insert variables received form an input form. When I put
the variable names in place of the literals like this:
SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES(EmpName, DateOfAccident, NotifyDate)"
I get this error message:
No value given for one or more required parameters

What is the syntax for using variables as the values?
An SQL statement is a string like any other string, so you concatenate your
variables in the usual way:

SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate, TheNotifyDate)V ALUES('"
+ EmpName + "' etc...

However, this is an extremely dangerous practice, especially in a web
application, because of something called SQL Injection, but maybe that's
another story for another day...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #6
Hi Mark,

Can you tell me why I get a new record, but with nothing in it, even though
I get a form and fill it in and click submit?
Here's the code:
<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="Syst em.Data.Oledb" %>

<script language= "VB" runat="server">

'Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s)

Sub btnSendDatabase _OnClick(Source As Object, E As EventArgs)
Dim DBConnection As OledbConnection

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

"Data Source=C:\Inetp ub\wwwroot\Acc. mdb" )

DBConnection.Op en()

Dim DBCommand As OledbCommand

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

Dim SQLString AS String
Dim EmpName as String

Dim DateOfAccident as string

Dim NotifyDate as string
SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES('"+EmpNam e+"','"+DateOfA ccident+"','"+N otifyDate+"')"

DBCommand = New OleDBCommand(SQ LString, DBConnection)

DBCommand.Execu teNonquery()
DBConnection.Cl ose()

End Sub

</script>

</head>

<body>

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

Employee's Name: <asp:textbox id="EmpName" runat=server columns="45"/>

<asp:textbox id="DateofAccid ent" runat=server /></asp:textbox>

<font face="Verdana" Size="2">Date Employer Notified <asp:textbox
id="Notifydate " runat=server/>

<asp:Button id="btnSendData base" text="Submit"
OnClick="btnSen dDatabase_OnCli ck" runat="server" />
</form>

</body>

</html>





"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:eL******** ******@TK2MSFTN GP02.phx.gbl...
"dancer" <da****@microso ft.comwrote in message
news:eC******** ******@TK2MSFTN GP02.phx.gbl...

Jul 17 '07 #7
"dancer" <da****@microso ft.comwrote in message
news:eZ******** ******@TK2MSFTN GP02.phx.gbl...
Can you tell me why I get a new record, but with nothing in it, even
though I get a form and fill it in and click submit?
A couple of things...

Firstly:
Dim DBCommand As OledbCommand
DBCommand = New OledbCommand("S ELECT * FROM table1, Acc")
You're instantiating an OleDbCommand object, but never actually using it
before re-instantiating it further down in the code...
Secondly:
Dim SQLString AS String
Dim EmpName as String
Dim DateOfAccident as string
Dim NotifyDate as string

SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES('"+EmpNam e+"','"+DateOfA ccident+"','"+N otifyDate+"')"
DBCommand = New OleDBCommand(SQ LString, DBConnection)
DBCommand.Execu teNonquery()
DBConnection.Cl ose()
You're not actually populating the three data variables - therefore, you're
inserting a record into your table where all the fields are blank...

Dim EmpName as String = EmpName.Text
Dim DateOfAccident as string = DateOfAccident. Text
Dim NotifyDate as string = NotifyDate.Text
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #8
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:Og******** ******@TK2MSFTN GP06.phx.gbl...
Dim EmpName as String = EmpName.Text
Dim DateOfAccident as string = DateOfAccident. Text
Dim NotifyDate as string = NotifyDate.Text
Actually, that might cause errors because the string variables have the same
names as the webcontrols...

Dim SQLString AS String
Dim strEmpName As String = EmpName.Text
Dim strDateOfAccide nt As String = DateOfAccident. Text
Dim strNotifyDate As String = NotifyDate.Text

SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate)V ALUES('"+ strEmpName+"',' "+ strDateOfAccide nt+"','"+
strNotifyDate+" ')"
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #9
ok It's working now. Thanks

Now - other question - I have 47 fields. Do I have to code '"+field1+"' ,
etc. 47 TIMES?!!
Is there not a way to say INSERT INTO Table 1 [all] VALUE [all] in some
form?
SURELY there is a way.

Also, I have seen
With Cmd Parameters
.Add(New OleDbParameter( "@field1",
frmfield1.text) )
etc.
What is the difference in that and INSERT?

Thank you.

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:Og******** ******@TK2MSFTN GP06.phx.gbl...
"dancer" <da****@microso ft.comwrote in message
news:eZ******** ******@TK2MSFTN GP02.phx.gbl...
>Can you tell me why I get a new record, but with nothing in it, even
though I get a form and fill it in and click submit?

A couple of things...

Firstly:
>Dim DBCommand As OledbCommand
DBCommand = New OledbCommand("S ELECT * FROM table1, Acc")

You're instantiating an OleDbCommand object, but never actually using it
before re-instantiating it further down in the code...
Secondly:
>Dim SQLString AS String
Dim EmpName as String
Dim DateOfAccident as string
Dim NotifyDate as string

SQLString = "INSERT INTO Table1(TheEmpNa me, TheDate,
TheNotifyDate) VALUES('"+EmpNa me+"','"+DateOf Accident+"','"+ NotifyDate+"')"
DBCommand = New OleDBCommand(SQ LString, DBConnection)
DBCommand.Exec uteNonquery()
DBConnection.C lose()

You're not actually populating the three data variables - therefore,
you're inserting a record into your table where all the fields are
blank...

Dim EmpName as String = EmpName.Text
Dim DateOfAccident as string = DateOfAccident. Text
Dim NotifyDate as string = NotifyDate.Text
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8576
by: CSDunn | last post by:
Hello, I have an Access 2000 Project in which the data comes from a SQL Server 2000 database, and multiple users need to be able to see new records as each user adds records. The users also need to be aware of updates as they are made to current records. The data the users are looking at is presented in a subform that has the Default View property set to 'Single Form'. In order for each user to see the update to the current record as...
1
1698
by: Liz | last post by:
I have a table of about 10,000 records where each record has a numeric field named RecIdent. The value of RecIdent starts at 1 and is not sequential. For a given RecIdent, there may be only one record with that value or there could be multiple records with the same value. A sample of records looks like: PK RecIdent 1 1 2 3 3 3 4 5
6
2506
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
6
3103
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from the table, but I was not allowed to do that, because "there are records related with those PRODUCTS in other tables (e.g. in table "ORDER_DETAIL").
5
29010
by: Grant | last post by:
Hi Is there a way to recover deleted records from a table. A mass deletion has occurred and Access has been closed since it happened Louis
6
2133
by: Damon Grieves | last post by:
Hi I just want to be sure I understand how the Access client works. If I have an Access back end with a million records on a server and an Access client. If the client is installed on the users pc and run by the user...does Access drag the whole million records across the LAN when we call up one record ie filters for that record locally? If the client is on the same server as the back end, and the user starts up the client on the server...
13
3478
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the query: QryICTMassDistribution3) , I then use a form and the code below to create a new record in the corrispondence table to show what corrispondence has been sent to various companies.
1
2396
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting about 80 records from the Orders table. 80 out of a 1000 records. Now our data entry form shows our customer addresses, but not customer order history. When looking at all of the tables, customer, payments, orders, they still have all of the...
4
3226
by: LetMeDoIt | last post by:
Greetings, I'm using ASP to retrieve from MSSQL and I then populate a table. After several months of successfull retrieves, this same code now bombs out. It turns out that if I clear out from SQL about 10,000 records, the retrieve is then successfull. Reading some of the posts, I believe I need to set the cache. If anyone can point out where that cache, it would be greatly appreciated...
11
3674
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From the mother table, the incentive is calculated datewise for each employee as per his shift duty. In...
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.