473,763 Members | 8,980 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
14 1613
Yes, I got an error, so I put Dim TheEmpName as String = EmpName.Text, etc.,
which makes the names in the table the same as the variable names. It
works, but will it be a problem?

Thanks


"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:OH******** ******@TK2MSFTN GP04.phx.gbl...
"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 #11
"dancer" <da****@microso ft.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Now - other question - I have 47 fields. Do I have to code '"+field1+"' ,
etc. 47 TIMES?!!
Yes.
Is there not a way to say INSERT INTO Table 1 [all] VALUE [all] in some
form?
No.
SURELY there is a way.
You could play about with generics and dictionaries and goodness knows what
but, at the end of the day, you can't really get away from the fact that
you've to send your database a piece of SQL, so you may as well just build
it...
Also, I have seen
With Cmd Parameters
.Add(New OleDbParameter( "@field1",
frmfield1.text) )
etc.
What is the difference in that and INSERT?
That's parameterisatio n - a much safer way of constructing database writes
which helps to eliminate SQL Injection. You would be well advised to adopt
this method.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #12
"dancer" <da****@microso ft.comwrote in message
news:uW******** ******@TK2MSFTN GP04.phx.gbl...
Yes, I got an error, so I put Dim TheEmpName as String = EmpName.Text,
etc., which makes the names in the table the same as the variable names.
It works, but will it be a problem?
No.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #13
RE: Cmd parameters Oh I would like to try that. But every time I try I get
all kinds of errors.
What does the @ mean? Do you have to declare @something or does the
compiler understand the @ as something special?
("@something " , frmsomething.te xt))
Could you define the above?

By injection you mean the user adding an ' in the data?

Thank you very much.

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:uU******** ******@TK2MSFTN GP05.phx.gbl...
"dancer" <da****@microso ft.comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Now - other question - I have 47 fields. Do I have to code '"+field1+"' ,
etc. 47 TIMES?!!

Yes.
>Is there not a way to say INSERT INTO Table 1 [all] VALUE [all] in some
form?

No.
>SURELY there is a way.

You could play about with generics and dictionaries and goodness knows
what but, at the end of the day, you can't really get away from the fact
that you've to send your database a piece of SQL, so you may as well just
build it...
>Also, I have seen
With Cmd Parameters
.Add(New OleDbParameter( "@field1",
frmfield1.text ))
etc.
What is the difference in that and INSERT?

That's parameterisatio n - a much safer way of constructing database writes
which helps to eliminate SQL Injection. You would be well advised to adopt
this method.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #14
"dancer" <da****@microso ft.comwrote in message
news:O1******** ******@TK2MSFTN GP06.phx.gbl...
RE: Cmd parameters Oh I would like to try that. But every time I try I
get all kinds of errors.
http://www.java2s.com/Code/VB/Databa...dParameter.htm
By injection you mean the user adding an ' in the data?
No I don't - I mean this:
http://www.google.co.uk/search?sourc...L+Injection%22
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 17 '07 #15

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

Similar topics

3
8577
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
1699
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
3104
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
29014
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
2134
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
3479
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
2397
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
3677
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
9564
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
10148
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
10002
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
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.