Advertisement

05.08.2008 at 05:40PM PDT, ID: 23388137 | Points: 125
[x]
Attachment Details
Simple MSSQL standard 2005 queries in ASP.net on Windows Server 2003 IIS6
title says it all, I just want a simple example foir update, remove, select, and insert into because I cannot find example code or a guide or anything on this anywhere

DB: Maintenance
Table: Requests

also I think it is connecting cause the connection code by itself will work.



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
 
<script runat="server">
 
    Sub Page_Load(sender As Object, e As EventArgs)
    'declarations
    Dim connection As SqlConnection
    
    connection = New SqlConnection( _
                  "server=127.0.0.1;uid=UT;pwd=pass; " & _
                  "database=Maintenance")
    connection.Open
 
	Dim command As New SqlCommand("INSERT INTO Requests", connection)
        command.Connection.Open()
        command.ExecuteNonQuery()
 
 
    'cmdLath = New SqlCommand ( _
    '           "select idno,yr,txt from latham", _
    '              conLath)
    'rdrLath = cmdLath.ExecuteReader
    'gridLath.DataSource = rdrLath
    'gridLath.DataBind
    'rdrLath.Close
    'cmdLath.Dispose
    connection.Close
    End Sub
 
</script>
 
 
continue with the html part of page
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: Titanium_Sniper
Question Asked On: 05.08.2008
Participating Experts: 1
Points: 125
Views: 0
Translate:
Loading Advertisement...
05.08.2008 at 05:45PM PDT, ID: 21529661

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:45PM PDT, ID: 21529665

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:47PM PDT, ID: 21529670

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:48PM PDT, ID: 21529673

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:49PM PDT, ID: 21529682

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:50PM PDT, ID: 21529683

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:51PM PDT, ID: 21529688

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:52PM PDT, ID: 21529691

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:57PM PDT, ID: 21529705

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 05:59PM PDT, ID: 21529710

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:01PM PDT, ID: 21529718

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:01PM PDT, ID: 21529720

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:03PM PDT, ID: 21529728

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:04PM PDT, ID: 21529732

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:05PM PDT, ID: 21529736

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:11PM PDT, ID: 21529764

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.08.2008 at 06:12PM PDT, ID: 21529765

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.08.2008 at 05:45PM PDT, ID: 21529661
This page has it all.  Examples of how to do these statements in all asp.net type controls

http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm

 
05.08.2008 at 05:45PM PDT, ID: 21529665
If you would like something more advanced than the great examples on this page...just let me know
 
05.08.2008 at 05:47PM PDT, ID: 21529670
I will say your insert statement doesnt make sense...

you would insert into a table some set of values ..
 
05.08.2008 at 05:48PM PDT, ID: 21529673
HEre are example syntax for select, update, and delete
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
SELECT Syntax - Get Information from a table in database
SELECT ColumnName1,ColumnName2, ColumnName3 FROM TableName
SELECT DISTINCT ColumnName FROM TableName
SELECT COUNT (ColumnName) FROM TableName
SELECT ColumnName FROM TableName WHERE ColumnName = value
SELECT ColumnName FROM TableName WHERE ColumnName1 = value AND ColumnName2 = value
SELECT ColumnName FROM TableName WHERE ColumnName1 = value OR ColumnName2 = value
SELECT ColumnName FROM TableName WHERE ColumnName IN (Value1,Value2)
SELECT ColumnName FROM TableName WHERE ColumnName BETWEEN (Value1 AND Value2) 
SELECT ColumnName FROM TableName WHERE ColumnName Like '%Value1%' 
SELECT ColumnName FROM TableName ORDER BY ColumnName
SELECT ColumnName1 , SUM(ColumnName2 ) FROM TableName GROUP BY ColumnName1 HAVING (Arithematic Condition)
 
UPDATE Syntax
UPDATE TableName SET ColumnName = Value WHERE {Condition}
UPDATE TableName SET ColumnName = Value WHERE ColumnName = value
 
DELETE Syntax
DELETE TableName WHERE {Condition}
DELETE TableName WHERE ColumnName = value
Open in New Window
 
05.08.2008 at 05:49PM PDT, ID: 21529682
Thanks for the quick response, I will look at it right away
 
05.08.2008 at 05:50PM PDT, ID: 21529683
a sample insert would be like this

INSERT INTO Store_Information (store_name, Sales, Date)
VALUES ('Los Angeles', 900, 'Jan-10-1999')


attached are more complex insert statements


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
The INSERT statement allows you to insert a single record or multiple records into a table.
 
The syntax for the INSERT statement is:
 
INSERT INTO table
(column-1, column-2, ... column-n)
VALUES
(value-1, value-2, ... value-n);
 
 
 
Example #1 - Simple example
 
Let's take a look at a very simple example.
 
INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(24553, 'IBM');
 
This would result in one record being inserted into the suppliers table. This new record would have a supplier_id of 24553 and a supplier_name of IBM.
 
 
 
Example #2 - More complex example
 
You can also perform more complicated inserts using sub-selects.
 
For example:
 
INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE city = 'Newark';
 
By placing a "select" in the insert statement, you can perform multiples inserts quickly.
 
With this type of insert, you may wish to check for the number of rows being inserted. You can determine the number of rows that will be inserted by running the following SQL statement before performing the insert.
 
SELECT count(*)
FROM customers
WHERE city = 'Newark';
Open in New Window
 
05.08.2008 at 05:51PM PDT, ID: 21529688
And one final note about these types of database commands...ever since the rollout of ASP.net 2.0 alot of this is built in to the sqldatasource control.  Read up on that on the page link I gave you ....it save alot of time once you get used to it compared to the ado.net your are coding here:)
 
05.08.2008 at 05:52PM PDT, ID: 21529691
I need to know how to do the requests in ASP.net, I am ok at formatting SQL statements but nothing I try works to execute an insert.
 
05.08.2008 at 05:57PM PDT, ID: 21529705
<asp:SqlDataSource id="BookSource" Runat="Server"
  ProviderName="System.Data.OleDb"
  ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;
                    Data Source=c:\eCommerce\Databases\BooksDB.mdb"
  SelectCommand="SELECT BookID, BookType, BookTitle, BookPrice FROM Books
                 WHERE BookType = 'Database'
                 ORDER BY BookTitle"/>


how do I go from this to my SQL database, I have no clue about access.
 
05.08.2008 at 05:59PM PDT, ID: 21529710
Dim command As New SqlCommand("INSERT INTO Requests", connection)
This statement is not a valid insert statement if you do this the ado.net way...everything else looks good.

if you do it the sqldatasource way I can give you an example of that...


the line should be something like this:

dim insertstring as string = "Insert into Requests(col1, col2) Values (1,2)"
Dim command As New SqlCommand(insertstring, connection)


 
05.08.2008 at 06:01PM PDT, ID: 21529718
Here is how I do my sqldatasource control

<asp:SqlDataSource ID="SelectSource" runat="server"
      ConnectionString="<%$ ConnectionStrings:MidwareConnectionString %>"
      DataSourceMode="DataReader"/>
 
05.08.2008 at 06:01PM PDT, ID: 21529720
I will be using the sqldatasource way since you recommend it and I know how smart you are from your numerous points on this site
 
05.08.2008 at 06:03PM PDT, ID: 21529728
The connection string is stored in my webconfig file ...here is a snippit of that line in the webconfig:
1:
2:
3:
4:
5:
6:
7:
<configuration>
<connectionStrings>
<add name="MidwareConnectionString" connectionString="Data Source=myServer;Initial Catalog=myTable;User ID=user;Password=password" providerName="System.Data.SqlClient"/>
	</connectionStrings>
	<system.web>
 
and so on......
Open in New Window
 
05.08.2008 at 06:04PM PDT, ID: 21529732
its better to always store connection strings in the webconfig like such..or even in a dll...its more consistent and its more secure
 
05.08.2008 at 06:05PM PDT, ID: 21529736
thanks, it looks like a lot of info to do it the correct way, I'd better read that guide before I end up confuesing myself.
 
05.08.2008 at 06:11PM PDT, ID: 21529764
hehe..ok...just remember the datasource control ...simply connects to whatever datasource you want....
excel, odbc, sql server, access, sitemaps, active directory....u name it..

then you can bind a grid, dropdownlist, or any other control to that control by simply saying that the datasource of that control belongs to that datasource...

Then you can either assign your sql statements in the aspx source with the datasource control...which is what the examples on that site will show you...

or you can get more dyanamic..and assign them on page events ...like page load...or whatever event works for your solution.

good luck..and let me know if you have other questions
 
05.08.2008 at 06:12PM PDT, ID: 21529765
and by the way..ado.net is not an incorrect way...its just not as fast and effecient as using the new controls asp.net 2.0 provides....I still work with programmers who are still stuck inthe old ado.net way.....b/c for them its faster...but once you get this new way down..it saves significant programming time..and makes your code more reusable in the future...
 
 
20080236-EE-VQP-29 / EE_QW_EXPERT_20070906