Question

In: Computer Science

Create a new website using C# & ASP.Net in Visual Studio: 1. Create a web page...

Create a new website using C# & ASP.Net in Visual Studio:

1. Create a web page to access a database and display the data from a table by providing an SQL statement. Create the page with these requirements:

    create label, textbox and button
    the textbox will capture the SQL statement
    the button will process the statement and display the results

2. Add necessary data access pages to your project.

3. Display the data in Gridview

Solutions

Expert Solution

//Create Asp.net web application in Visual Studio and create an empty web application.

//Add database to ASP.NET project

By right-clicking on structure in solution explorer => Add -> new Item -> data -> sql database (.mdf)

Now go to table folder -> right click -> add new Table --> design table.

Now right click on Table (StudentData) and select show table data -> add new data into it.

Save the table and close it.

Now add a webform

//Design form using toolbox.

//Webform1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="data_access.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Query: "></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtQuery" runat="server" Width="396px"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnRunQuery" runat="server" OnClick="btnRunQuery_Click" Text="Run" />
<br />
<asp:GridView ID="grdViewData" runat="server">
</asp:GridView>
<br />
</div>
</form>
</body>
</html>

//=====================================

Now double click on run button -> Create a on click event (event name depends on whatever id you have given to button)

//===============================

Note:--> you can get the connection string by right clicking student.mdf in solution explorer, which will be passed into SqlConnection.

//Webform1.aspx.cs

using System;
using System.Data.SqlClient;
using System.Data;
namespace data_access
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection connection = null;
protected void Page_Load(object sender, EventArgs e)
{
connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\student.mdf;Integrated Security=True");
connection.Open();
}

protected void btnRunQuery_Click(object sender, EventArgs e)
{
string query = txtQuery.Text;
SqlCommand cmd = new SqlCommand(query,connection);
SqlDataAdapter sqlData = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sqlData.Fill(ds);
grdViewData.DataSource = ds.Tables[0];
grdViewData.DataBind();
connection.Close();
}
}
}

//Output

//If you need any help regarding this solution ........ please leave a comment ....... thanks


Related Solutions

Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has...
Create an ASP.Net Website using Visual Studio with Visual Basic.Net: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select (...
C# ( asp.net ) 2019 Visual Studio I have a dropdown where you can select ( integer, string, date ) After selecting the desired dropdown option, user can input a list of inputs. For example; for integer: 2,5,7,9,1,3,4 And then , I have a 'sort' button Can you please help me with the code behind for sorting them( For integer, string, and date ) Thank you.
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date"...
C# ( asp.net ) 2019 visual studio I have a dropdown option. If I choose "date" option, I get to enter list of dates like 02/08/1990, 06/14/1890 in (mm/dd/YYYY) format. How can I sort these dates in ascending order?. Can you provide me some code. Thank you
Using Visual Studio in C#; create a grading application for a class of ten students. The...
Using Visual Studio in C#; create a grading application for a class of ten students. The application should request the names of the students in the class. Students take three exams worth 100 points each in the class. The application should receive the grades for each student and calculate the student’s average exam grade. According to the average, the application should display the student’s name and the letter grade for the class using the grading scheme below. Grading Scheme: •...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
For your final project, you are to create a two-page web application of your choice. ASP.NET...
For your final project, you are to create a two-page web application of your choice. ASP.NET : C# You must include the following items: At least 5 different standard server controls At least 2 validation controls At least 1 navigation control ~ one must navigate back and forth to each page One session state element Upon completion of your two-page web application, you will provide a two page report describing the functions of the web application as well as each...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...
Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This project will be used to calculate the area of certain figures, like circles, squares and rectangles. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String...
Instructions (No array) (c++) (visual studio) 1. Create a project called Project3B 2. Create 3 String variables called name1, name2, name3 3. Create 9 double variables called test1_1, test1_2, test1_3, test2_1, test2_2, test2_3, test3_1, test3_2, test3_3 4. Create 3 double variables called average1, average2, average3 To calculate the average score = (test1 + test2 + test3) / 3.0 5. Run the program with the following data using cin name1 = “Tom”, name2 = “Mary”, name3 = “Ali” test1_1 = 81.4,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT