Inserting a SQL Server record Using FormView and Returning the RecordID GUID
by admin on Jan.23, 2012, under ASP.Net
Create the following stored procedure:
create PROCEDURE [dbo].[sp_my_Insert]
@RecordID uniqueidentifier,
... --Other parameters
AS
begin
declare @RecordID uniqueidentifier
set @RecordID = newid()
INSERT into WorkOrders
(
RecordID,
...
)
VALUES
(
@RecordID,
...
)
IF @@ERROR = 0 AND @@ROWCOUNT = 1
BEGIN
/* This GUID will be returned to the client as a recordset */
SELECT @RecordID AS '@GUID'
RETURN 0
END
ELSE
BEGIN
RAISERROR('SQL Server Error', 16, 1)
RETURN -1
END
end
Once you create a FormView and bind it’s labels, add the following code to the ItemInserting event with your stored procedure:
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
string query = "You insert stored proceedure here";
Guid ID;
string connect = WebConfigurationManager.ConnectionStrings["Your web.config connection string name here"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connect))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.CommandType = CommandType.StoredProcedure;
//Get parameters from Form View and match them with the stored proceedure's parameters
cmd.Parameters.AddWithValue("@RecordID", recordID);
foreach (DictionaryEntry entry in e.Values) // Loop through all of the fields
{
//entry.Key = Bind variable parameter
//entry.Value = Label value
cmd.Parameters.AddWithValue("@" + entry.Key, entry.Value);
}
conn.Open();
ID = (Guid)cmd.ExecuteScalar(); // The GUID is returned here
}
}
}
Installing and Using Ajax Control Toolkit
by admin on Nov.23, 2011, under Uncategorized
Download the Ajax Control Toolkit from: http://ajaxcontroltoolkit.codeplex.com/releases/view/76976
For use with Visual Studio 2010:
AjaxControlToolkit.Binary.NET4.zip
application, 7493K, uploaded Nov 16 – 8171 downloads
For use with Visual Studio 2008:
AjaxControlToolkit.Binary.NET35.zip
application, 7482K, uploaded Nov 16 – 3235 downloads
More installation instructions can be found at http://www.asp.net/ajaxlibrary/act.ashx
- Download and extract the zip files in the default folder.
- Launch Visual Studio and create a new ASP.NET Web Forms project or website. Open Default.aspx in the Visual Studio editor.
- Create a new Toolbox tab by right-clicking the Toolbox and selecting Add Tab. Name the new tab Ajax Control Toolkit.
- Right-click beneath the new tab and select the menu option Choose Items… Click the Browse button and browse to the folder where you extracted the Ajax Control Toolkit. Pick the AjaxControlToolkit.dll and click the OK button to close the Choose Toolbox Items dialog.
To use the Ajax Control Toolkit1.
1. Add the following to the web.config file:
<system.web>
…
<pages>
<controls>
<add tagPrefix=”act” namespace=”AjaxControlToolkit” assembly=”AjaxControlToolkit”/>
</controls>
</pages>
</system.web>
2. Drag and drop the Toolkit Script Manager control onto the page
3. Drag and drop the desired control onto the page
4. The <%@ Register assembly=”AjaxControlToolkit” namespace=”AjaxControlToolkit” tagprefix=”asp” %> should now be added to the top of the page (done automatically). Change the tagprefix attribute from asp to act. The tag sould now look like this:
<%@ Register assembly=”AjaxControlToolkit” namespace=”AjaxControlToolkit” tagprefix=”act” %>
5. After adding them to the page, change the prefixes of all Toolkit Script Manager controls from asp to act. For example, the Toolkit Script Manager control should look like this:
<act:ToolkitScriptManager ID=”ToolkitScriptManager1″ runat=”server”>
A ComboBox tag sould look like this:
<act:ComboBox ID=”ComboBox1″ runat=”server”>
<asp:ListItem Value=”0″>Mild</asp:ListItem>
<asp:ListItem Value=”1″>Medium</asp:ListItem>
<asp:ListItem Value=”2″>Hot</asp:ListItem>
</act:ComboBox>
Parameterized Queries
by admin on Mar.22, 2011, under SQL Server
There’s a great tutorial by Gregory A. Larsen that can be found at http://www.databasejournal.com/features/mssql/article.php/3834501/Parameterized-Queries.htm?comment=53514-0 about using Parametrized queries (known as Bind Variables in Oracle) in SQL Server.
RunSQL App
by admin on Mar.13, 2011, under Current Projects
I am currently working on a little Java app that will read from a list of SQL files and run each one. It’s for the Gus scheduler at Icelandic. It also creates a log file that shows each successful run and any errors that might occur. It’s increased my skill at handling Java errors and using the Logger API.
Getting Started with Java, Eclipse, and Tomcat
by admin on Mar.06, 2011, under Notes
To find good tutorials for Java, Eclipse, JSP, and Tomcat: http://www.vogella.de/.
For Java installation and basic Java development: Vogella’s Introduction to Java Programming located at http://www.vogella.de/articles/JavaIntroduction/article.html.
To install Eclipse and for learning how to write a simple Java application: Vogella’s Eclipse IDE Tutorial located at http://www.vogella.de/articles/Eclipse/article.html.
Using Eclipse for web development: Vogella’s Servlet and JSP Developement with Eclipse located at http://www.vogella.de/articles/EclipseWTP/article.html.
Installing Tomcat on Windows
by admin on Mar.06, 2011, under How To Step By Step
The easiest way to install Tomcat on Windows is to use the 32-bit/64-bit Windows Service Installer located at http://tomcat.apache.org/download-60.cgi. This is Version 6. I don’t suggest installing Version 7 because at the time time of this writing, that version has a bug which affects running servlets.
Once downloaded, run it and follow these steps:
- Click next on the Welcome screen. If you accept the license agreement click I Agree.
- Leave all of the components on default and click next.
- You can leave the Connector port as 8080 if you don’t mind typing in it at the end of URL. For instance, you’d have to type “http://localhost:8080″ as an address to bring up web pages with Tomcat running on your PC. Web Browsers default to port 80, therefore the port number isn’t required at the end of the address in that case. For instance, you would only have to type “http://localhost” using this port number. I suggest setting this port to 80, unless your running another web server on the same computer.
- I never leave my Tomcat server running unless I’m developing on it, so I don’t enter Administer user name and password. Tomcat will install and run without it. It would be a different story, however, if your installing Tomcat on a production server.
- Navigate to the location of your Java JRE files. Mine is in the default location of C:\Program Files\Java\jre6. Click Next.
- The default location of the install is C:\Program Files\Apache Software Foundation\Tomcat 6.0. I like to install it at the root of my C drive because it’s easier to navigate to it there. I also like to take out the version number. This makes it easier to install later versions by not having to change the paths of other applications that use it. So my installation path is C:\tomcat. Click Install.
- Once the install is complete, leave the check boxes checked and run Tomcat. You will see the readme files. You can read these and close them.
- You will see the Apache Commons Daemon Service Manager window appear with a progress bar. Once completed, Tomcat will be running in the background.
- Test it by opening up your favorite browser (Firefox is mine!) and entering http://localhost in the address bar. If you used the default port, then you will need to enter http://localhost:8080 in the address bar. If all is working correctly, you see the following:

JSP Page to Display HTML Form
by admin on Mar.05, 2011, under Snippets
<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″ pageEncoding=”ISO-8859-1″%>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″>
<title>Hello you</title>
</head>
<body>
<form action=”hello.jsp” method=”get”>
First name: <input type=”text” name=”firstName” /><br />
Last name: <input type=”text” name=”lastName” /><br />
<input type=”submit” value=”Submit” />
</form>
</body>
</html>
HTML Form
by admin on Mar.05, 2011, under Snippets
<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
pageEncoding=”ISO-8859-1″%>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″>
<title>Insert title here</title>
</head>
<body>
<% // Get the parameters from the request
String firstName = request.getParameter(“firstName”);
String lastName = request.getParameter(“lastName”);
%>
Hello <%= firstName %> <%= lastName %>!
</body>
</html>