-->

Monday, September 14, 2015

Calculate number of records in Gridview when it bind with SqlDataSource

Introduction

In this article i will show you how to calculate number of records in database table. This is possible through SqlDataSource class. You can call AffectedRows property  of the SqlDataSource. So lets take a example of count numbers of records in database table.


Source Code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default17.aspx.cs" Inherits="Default17" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Emp_Name" HeaderText="Emp_Name" SortExpression="Emp_Name" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" OnSelected="SqlDataSource1_Selected" SelectCommand="SELECT * FROM [Employee]"></asp:SqlDataSource>
        Total Number of records:
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>

Code Behind Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default17 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        Label1.Text = e.AffectedRows.ToString();
    }
Code generate the following output

Calculate number of records in Gridview when it bind with SqlDataSource


Friday, September 11, 2015

Retrieving Data Using a DataReader in ASP.NET C#

Introduction
In this article i will show you, how to retrieve data from database table using DataReader. I will give a example of data fetching from database table using SqlDataReader class, also bind the GridView with the DataReader.
SqlDataReader 
Provides a way of reading a forward-only stream of rows from a SQL Server database ( source from msdn.microsoft.com)

Example How to bind gridview using SqlDataReader class

Step-1 : Take a Gridview onto design window. 
Step-2 :  Develop code for binding gridview using SqlDataReader.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class datareadercl : System.Web.UI.Page
{
    SqlDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            using (SqlConnection con = new SqlConnection())
            {
                con.ConnectionString =ConfigurationManager.ConnectionStrings ["ConnectionString"].ToString ();
                con.Open ();
                using(SqlCommand cmd=new SqlCommand ())
{
                    cmd.CommandText ="select * from [Table]";
                    cmd.Connection =con;
                    rd=cmd.ExecuteReader();
                    GridView1 .DataSource =rd;
                    GridView1 .DataBind ();                  
 
}

            }
        }
    }
}

OutPut of the program


bindgridview
Read() method of SqlDataReader class  : read next record


September 22 Microsoft Office 2016 launch date fixed

Microsoft proclaimed this morning the official launch date for the long-anticipated remake of Microsoft office. office 2016 are going to be loosely out there beginning on September 22, the corporate says. Meanwhile, office Customers with volume licensing agreements are going to be ready to download the package on October 1.


The updated version of office includes variety of latest options for desktop customers, together with the power to co-edit documents at identical time, synchronize files to One Drive within the cloud, and more.

Alongside the announcement of the launch date, Microsoft noted a number of different new options and choices for IT admins and businesses wanting to deploy the software package.

For starters, the corporate noted that office 365 Pro Plus customers WHO square measure paying for the subscription version of workplace for corporations, also will receive the “Current Branch” – that means the foremost up-to-date feature unleash and security updates – on September 22. This unleash also will embody the new office 2106 app updates.

But supported client feedback, Microsoft says it’s introducing a brand new update model referred to as “Current Branch for Business,” which is able to offer 3 additive feature updates annually, whereas continued to supply monthly security updates. this can be designed for organizations that wish to check new releases of office 2016 before rolling out the new options, a Microsoft journal post explains.

Thursday, September 10, 2015

BulletedList Web Server Control Overview, binding with Sql Server in ASP.NET C#

Introduction
In this article example i will show you how to bind bulleted list web server control with sql server database. In previous article i explained use of it control using visual studio like how to add value in it at compile time. Lets see the example of bulleted list, which is bind with sql datasource control.


Following some steps for binding bulleted list control using SqlDataSource

Step-1 : Open visual studio
Step-2:  Click  File-->New-->WebSite

starting screen

Step-3: Right click on website name in solution explorer, Add-->Add new item 

web form


Step-4: Make Database table 
Step-5: Drag Bulleted list from toolbox and drop on design window.
Step-6: Select Show smart tag of Bulleted list

show smart tag

Step-7: On Bulledted list task click choose data source link
Step-8: Select New DataSource from Data Source configuration wizard.

choose data source

Step-9: Select SQL Database from Data Source Configuration wizard. and click ok button

data configuration wizard

Step-10 : Select existing database from configure data source.

connection string property

Step-11 : Change Connection name according to you and click "ok".

web.config file

Step-12 : Select table from name ,select table field name and press ok button

table view

Step-13: Click test query button and finish the process
Step-14: Select a data field to display in the bulleted list.
Step-15: Select a data field for the value of the bulleted list. and press ok button.
select one those field in bulleted list

Run your application

how to bind bulleted list in asp.net

Finally source of the code are:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name " DataValueField="Url">
        </asp:BulletedList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [mytab]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
Top Related Article

Check, if value exists in Database ASP.NET C#

Introduction
In this article i will show you availability of data in the database table, if exist then return true otherwise return false. In this article we will use linear search algorithm to search the data. So lets see the example of it.

follow some steps for checking data into database
Step 1: Create table in database  http://dotprogramming.blogspot.in/2013/06/how-to-make-database-table-in-visual.html

database table

table value




Step 2:  Take a web form name as "duplicatevalue.aspx"
Step 3:  Design a Webform

design form

Step 4: Make Connection string in web.config file

Step-5 : Create procedure for retrieving data 

CREATE PROCEDURE [dbo].[checkdata]

AS
SELECT * from [Table] 
RETURN 0



Step 6: Double click on "Check Existing" Button and make 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;
using System.Data;
using System.Configuration;
public partial class duplicatevalue : System.Web.UI.Page
{
    SqlDataReader rd;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = false;

        using (SqlConnection con = new SqlConnection())
        {
            con.ConnectionString =ConfigurationManager .ConnectionStrings ["ConnectionString"].ToString ();
            con.Open();
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "checkdata";
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                rd = cmd.ExecuteReader();
                while (rd.Read ())
                {
                    if (rd["EmployeeId"].ToString().Equals(empid.Text))
                    {
                        flag = true;
                        break;
                        

                    }
                }
                if (flag ==true)
                    result.Text = "ALREADY EXISTS";
                else
                    result.Text = "not existes";

                                
            }
        }

    }
}

Out put of the program
data exists
not exists

The same article we can do with different method check this article in different style.

Wednesday, September 9, 2015

Login form using entity framework in windows form c#

Introduction
In this article i will give an example of login form using entity framework. We will do login from database table so first of all create database table using entity framework's code first approach. Now, Using linq query we can do this task.

Description
Sometimes anonymous user can harm our application and can change the data stored in our application. That’s why, it is often necessary to permit only authorized users to use our application. There is no predefined method to do this operation in windows forms, so we have to implement it in our way.

If we have username and password in our database then we can implement a better authentication system. So we will create a table in our database named User which will have two columns (Username and Password). Insert some records in that table to check our login control.



In click event of login button write following code:


Here in this code will show a message if user leaves the textboxes empty. First check the username in our database having exactly the same name user entered in textbox. If there is an entry then compare the password.
We can show a message box at each wrong step of user.

Download example.

Tuesday, September 8, 2015

Button work as fileupload control in JQuery

Introduction

In this article i will show you how a button control behaves as fileupload control. Example of button control working as fileupload control. In this article i taken a button and fileupload control but visibility of fileupload is hidden. Get the fileupload control by their id property in JQuery and put the accessed file path into label control. Let see the example



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script>
    $(function(){
        $("#fileupload1").change(function () {
            $("#l1").html($("#fileupload1").val().substring($("#fileupload1").val().lastIndexOf("\\") + 1));

        });
    })
</script>
</head>
<body>
    <form id="form1">
        <input type="file" style="display:none" id="fileupload1"/>
        <input type="button" id="Button1" onclick='$("#fileupload1").click()' value="upload"/>
        <label id="l1"></label>

    </form>

</body>
</html>

Code generate the following output


Button work as fileupload control in JQuery

© Copyright 2013 Computer Programming | All Right Reserved