I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
Introduction
In previous article i explained how to create connection with MS-Access database; How to bind DataGrid with access database. In this article i will teach you how to insert item into Access database using ASP.NET C#. Lets take a simple example of inserting item into access database in asp.net.
Description
First of all create connection with the access database which is already done in previous article. Now, you will do some changes in code of GridView binding. Like replace DQL query with DML query.
Like :
cmd.CommandText = "Insert into [tablename](columnName)Values(Data)";
Also do not required to execute the query, use ExecuteNonQuery() method to insert data by the input box.
Source Code:
Source Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Name :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Enter Data into Excess" />
</div>
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Name :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Enter Data into Excess" />
</div>
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString=ConfigurationManager.ConnectionStrings["Connection"].ToString();
con.Open();
OleDbCommand cmd=new OleDbCommand();
cmd.CommandText = "insert into [Employee](Name1)values(@nm)";
cmd.Parameters.AddWithValue("@nm", TextBox1.Text);
cmd.Connection = con;
int a = cmd.ExecuteNonQuery();
if (a>0)
{
Label1.Text = "Inserted";
}
}
}
Code generate the following output
Comments
Post a Comment