'i am trying to run this data model code but error is all i get
// front end code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Student.aspx.cs" Inherits="nekmAdo.Student" %>
<title></title>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Student_Id</td>
<td>
<asp:TextBox Student_Id="txtStudent_Id"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Name</td>
<td>
<asp:TextBox Name="txtName"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<asp:TextBox Email="Email"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Join_Date</td>
<td>
<asp:TextBox Join_Date="Join_Date"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSubmit" runat="server"
Text="Submit" OnClick="btnSubmit_Click"/>
</td>
</tr>
<tr>
<td colspan="2">
<h5>Message: <asp:Label ID="lblMessage"
runat="server"></asp:Label></h5>
</td>
</tr>
</table>
</div>
</form>
// Back end code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace nkemAado
{
public partial class CreateStudent : System.Web.UI.Page
{
Protected void btnSubmit_Click(object Sender, EventArgs e)
{
string connectionString = @"Data Source=DESKTOP-5JPBK1L; Database=StudentDB;
Integration Security=SSPI";
STUDENT_TABLE student_table = new STUDENT_TABLE()
{
STUDENT_ID = Convert.ToInt32(txtStudent_Id.Text),
NAME = txtName.Text,
EMAIL = txtEmail.Text,
JOIN_DATE = DateTime.Parse(txtJoinDate.Text)
};
using (SqlConnection cn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(sql, cn))
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
try
{
using (StudentDBEntities StudentDB = new StudentDBEntities())
{
StudentDB.STUDENT_TABLE.Add(student_table);
StudentDB.SaveChanges();
}
lblMessage.Text = "Student Created successfully!";
}
catch (Exception excp)
{
lblMessage.Text = "Error: " + excp.Message;
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
