below i copied the whole code. (i cut down some irrelevant code to save the space)
================================================== ====================================
<%@ Page Language="C#" ContentType="text/html" debug="true" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="C#" runat="server" >
SqlConnection objConnection = null;
SqlCommand objCmd = null;
int Identity;
void Page_Load()
{
// make connection string
String strSQL;
String strConnection = "user id=XXX;password=YYY;";
strConnection += "initial catalog=ZZZ;server=XYZ;";
objConnection = new SqlConnection(strConnection);
objConnection.Open();
DataSet ds = new DataSet();
SqlDataAdapter daStates = new SqlDataAdapter("SELECT * FROM states ORDER BY stateName;", objConnection);
daStates.Fill(ds, "states");
stateList.DataSource = ds.Tables["states"];
stateList.DataBind();
}
private void Insert1(object sender, EventArgs e)
{
// set the SQL string
string strSQL = "INSERT INTO DCConfPerson ( " +
"firstName, middleName, lastName, " +
"address1, address2, city, state, zip, " +
"homePhone, mobilePhone, otherPhone) " +
"VALUES (" +
firstName.Text + "', '" +
middleName.Text + "', '" +
lastName.Text + "', '" +
title.Text + "', '" +
address1.Text + "', '" +
address2.Text + "', '" +
city.Text + "', '" +
stateList.SelectedItem + "', '" +
zip.Text + "', '" +
homePhone.Text + "', '" +
mobilePhone.Text + "', '" +
otherPhone.Text + ");" +
"SELECT @@IDENTITY AS 'Identity';";
// Create the Command and set its properties
SqlCommand objCmd = new SqlCommand(strSQL, objConnection);
// save Identity in a cookie
HttpCookie RegCookie = new HttpCookie("NewId");
RegCookie.Value = Convert.ToString(Identity);
Response.Cookies.Add(RegCookie);
// execute the command
objCmd.ExecuteNonQuery();
if (objConnection.State == ConnectionState.Open);
objConnection.Close();
Response.Redirect("register2.aspx");
}
</script>
|