I am completely new to ASP/C#/VisualStudio. I took a course and am trying to build my first project. I feel like if I could get past this hurdle I'm destined for greatness!
I am simply trying to create a page that will insert data into a database.
Below is the contents of my AddNewOrder.aspx file:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddNewOrder.aspx.cs" Inherits="MemberPages_AddNewOrder" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Order Database > Add New Order</title>
<link href="../StyleSheet.css" rel="stylesheet" />
<style type="text/css">
.auto-style1 {
height: 44px;
}
</style>
</head>
<body>
<div id="page">
<!--#include file="../Includes/sidebar.inc"-->
<div id="content">
<h1>Add New Order</h1>
<form id="form1" runat="server">
<table class="contenttablecontainer">
<tr>
<td>
<table class="newordertable">
<tr>
<td>Item Model:</td>
<td>
<asp:TextBox ID="Model" runat="server" Columns="40" Rows="6" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>Vendor:</td>
<td><asp:DropDownList ID="Vendor" runat="server" DataSourceID="VendorDataSource" DataTextField="VendorName" DataValueField="VendorName">
</asp:DropDownList>
<asp:SqlDataSource ID="VendorDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:Vendors_Connection %>" SelectCommand="SELECT DISTINCT [VendorName] FROM [vendors]"></asp:SqlDataSource>
</td>
</tr>
And below is the code from my AddNewOrder.aspx.cs file:
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
public partial class MemberPages_AddNewOrder : System.Web.UI.Page
{
string connString = ConfigurationManager.ConnectionStrings
["Orders_ConnectionString"].ConnectionString;
protected void AddOrderBtn_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand comm = new SqlCommand("AddNewOrderProc", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@Model", Model.Text);
comm.Parameters.AddWithValue("@Vendor", Vendor.Text);
try
{
conn.Open();
comm.ExecuteNonQuery();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
finally
{
conn.Close();
}
}
}
I am using Visual Studio Professional 2017.