Your SQL database should be connected to SharePoint. Here are the steps needed to run NET using C#. To open Visual Studio 2015 Update 3, go to the File > New > Project menu, or click on “Ctrl+Shift+N”. To create an ASP server for Visual C#, select nsite and undise Visual C# >> Web >> ASP. This Web Application belongs to the NET. A final click of the “OK” button will complete the process.
How Does Web Form Connect To Sql Server Database?
Choose your ASP software >>-new Project option. Web Applications, for both NET and.NET 2.0 are completely empty. You may select Connecting to Database under Tools in the top right corner after selecting the new project. The Add Connection dialogue box will appear, where you can click the new option and choose the Microsoft SQL Server setting. The server name will now appear on your screen.
Net Connect To Sql Server?
After that, the ASP will be created. Membership databases and school databases belonging to Net. Using Visual Web Developer, right-click Data Connection and select Create New SQL Server Database from the View menu; then select Server Explorer (Database Explorer). Click “Create New SQL Server Database” on the Create New SQL Server Database dialog box.
Step 1
Now, Open Visual Studio 2015 Update 3, go to the File >> New >> Project or use the shortcut key “Ctrl+Shift +N”.
Here, select Visual C# >> Web >> ASP.NET Web Application. Finally, click “OK” button.
Step 3
Here, you can select the template for your ASP.NET Application. We are choosing “Empty” here. Now, click OK button.
Now, open the project and look for the Solution Explorer.
Step 5
Here, the database and data are added.
Now, you can select the ConnectionString and Click NEXT button
- 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;
- using System.Configuration;
- namespace DatabaseConnectivity
- {
- public partial class loginpage System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if(IsPostBack)
- {
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[“RegiConnectionString”].ConnectionString);
- conn.Open();
- string checkuser = “select count(*) from RegisterDataBase where StudentName='”+TextBox1.Text+“‘”;
- SqlCommand cmd = new SqlCommand(checkuser, conn);
- int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString());
- if (temp == 1)
- {
- Response.Write(“Student Already Exist”);
- }
- conn.Close();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- try
- {
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[“RegiConnectionString”].ConnectionString);
- conn.Open();
- string insertQuery = “insert into RegisterDataBase(StudentName,Passwords,EmailId,Department,College)values (@studentname,@passwords,@emailid,@department,@college)”;
- SqlCommand cmd = new SqlCommand(insertQuery, conn);
- cmd.Parameters.AddWithValue(“@studentname”, TextBox1.Text);
- cmd.Parameters.AddWithValue(“@passwords”, TextBox2.Text);
- cmd.Parameters.AddWithValue(“@emailid”, TextBox3.Text);
- cmd.Parameters.AddWithValue(“@department”, TextBox4.Text);
- cmd.Parameters.AddWithValue(“@college”, TextBox5.Text);
- cmd.ExecuteNonQuery();
- Response.Write(“Student registeration Successfully!!!thank you”);
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(“error” + ex.ToString());
- }
- }
- }
- }
Now, you can see the Loginpage.aspx code.
- <%@ Page Language=“C#” AutoEventWireup=“true” CodeBehind=“loginpage.aspx.cs” Inherits=“DatabaseConnectivity.loginpage” %>
- <!DOCTYPE html>
- <html xmlns=“http//www.w3.org/1999/xhtml”>
- <head runat=“server”>
- <title></title>
- <link href=“stylepage.css” type=“text/css” rel=“stylesheet” />
- <style type=“text/css”>
- .auto-style1 {
- width 100%;
- }
- </style>
- </head>
- <body>
- <form id=“form1” runat=“server”>
- <div id=“title”>
- <h1>REGISTER PAGE</h1>
- </div>
- <div id =“teble”></div>
- <table class=“auto-style1”>
- <tr>
- <td>
- <aspLabel ID=“Label1” runat=“server” Text=“StudentName”></aspLabel></td>
- <td>
- <aspTextBox ID=“TextBox1” runat=“server”></aspTextBox></td>
- </tr>
- <tr>
- <td>
- <aspLabel ID=“Label2” runat=“server” Text=“Password”></aspLabel></td>
- <td>
- <aspTextBox ID=“TextBox2” runat=“server”></aspTextBox></td>
- </tr>
- <tr>
- <td>
- <aspLabel ID=“Label3” runat=“server” Text=“EmailId”></aspLabel></td>
- <td>
- <aspTextBox ID=“TextBox3” runat=“server”></aspTextBox></td>
- </tr>
- <tr>
- <td>
- <aspLabel ID=“Label4” runat=“server” Text=“Department”></aspLabel></td>
- <td>
- <aspTextBox ID=“TextBox4” runat=“server”></aspTextBox></td>
- </tr>
- <tr>
- <td>
- <aspLabel ID=“Label5” runat=“server” Text=“College”></aspLabel></td>
- <td>
- <aspTextBox ID=“TextBox5” runat=“server”></aspTextBox></td>
- </tr>
- </table>
- <div id=“button”>
- <aspButton ID=“Button1” runat=“server” Text=“submit” OnClick=“Button1_Click” BackColor=“Yellow” />
- </div>
- <div id=“sim”></div>
- <aspSqlDataSource ID=“SqlDataSource1” runat=“server” ConnectionString=“<%$ ConnectionStringsRegiConnectionString %>” SelectCommand=“SELECT * FROM [RegisterDataBase]”></aspSqlDataSource>
- <div id=“grid”>
- <aspGridView ID=“GridView1” runat=“server” AllowPaging=“True” AllowSorting=“True” AutoGenerateColumns=“False” CellPadding=“4” DataSourceID=“SqlDataSource1” ForeColor=“#333333” GridLines=“None”>
- <AlternatingRowStyle BackColor=“White” ForeColor=“#284775” />
- <Columns>
- <aspBoundField DataField=“Id” HeaderText=“Id” SortExpression=“Id” />
- <aspBoundField DataField=“StudentName” HeaderText=“StudentName” SortExpression=“StudentName” />
- <aspBoundField DataField=“Passwords” HeaderText=“Passwords” SortExpression=“Passwords” />
- <aspBoundField DataField=“EmailId” HeaderText=“EmailId” SortExpression=“EmailId” />
- <aspBoundField DataField=“Department” HeaderText=“Department” SortExpression=“Department” />
- <aspBoundField DataField=“College” HeaderText=“College” SortExpression=“College” />
- </Columns>
- <EditRowStyle BackColor=“#999999” />
- <FooterStyle BackColor=“#5D7B9D” -Bold=“True” ForeColor=“White” />
- <HeaderStyle BackColor=“#5D7B9D” -Bold=“True” ForeColor=“White” />
- <PagerStyle BackColor=“#284775” ForeColor=“White” HorizontalAlign=“Center” />
- <RowStyle BackColor=“#F7F6F3” ForeColor=“#333333” />
- <SelectedRowStyle BackColor=“#E2DED6” -Bold=“True” ForeColor=“#333333” />
- <SortedAscendingCellStyle BackColor=“#E9E7E2” />
- <SortedAscendingHeaderStyle BackColor=“#506C8C” />
- <SortedDescendingCellStyle BackColor=“#FFFDF8” />
- <SortedDescendingHeaderStyle BackColor=“#6F8DAE” />
- </aspGridView>
- </div>
- <div id=“last”>
- <h3>Developed by
- Muthuramalingam Duraipandi</h3>
- </div>
- </form>
- </body>
- </html>
Step 10
Step 11