Database Connectionstring connect from class library file using Asp.Net c#

Database Connectionstring connect from class library file

if we need Database  connectionstring get directly from webform cs file but this concept call from Class.cs file for hiding connection information using Asp.Net C#.

DEMO

HTML CODING

<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>

</head>
<body>
    <form runat="server">      
        <div align="center">

    
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="View" />
        <br />


        <asp:GridView ID="GridView1" runat="server"></asp:GridView></div>
        </form>
</body>
</html>


Class.cs File 


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


using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Class1
/// </summary>
///
public class dbconnection
{
       public SqlConnection connection()
       {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con.Open();
        return con;
       }
   
}


 C# Coding

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;

public partial class AngularJS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        dbconnection dbc = new dbconnection();
        SqlConnection con = dbc.connection();

        SqlCommand cmd = new SqlCommand("select * from register", con);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);

        DataSet ds = new DataSet();
        adp.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        con.Close();
    }
}



First add Class file - Right click - Add - Add New Item - add -Class.cs file 







add -Class.cs file 






Next - Add namespace   and call connection string to sqlconnection






Next - Call the class.cs library file  to Webform Codebehind file below like this














Mysql Storedprocedure OR Query Using in Asp.Net C#

Mysql Storedprocedure OR Query

If we search  to the database one condition or two condition set but now i am using or condition any one condition correct display the result using Mysql Storedprocedure in Asp.Net C#.


DEMO

MySql Stored Procedure



CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select_Date`(In vfromdate varchar(15),In vusername varchar(15))
BEGIN

select * from `userinformation` where fromdate=vfromdate or UserName=vusername;


END

Html Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">
    <table><tr><td>Username</td><td>
        <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
        </td></tr>
        <tr><td>Date</td><td>
            <asp:TextBox ID="txtDate" TextMode="Date" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td></td><td>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" style="height: 26px" />
            &nbsp;<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Reset" />
            </td></tr>
        <asp:GridView ID="GridView1" runat="server"></asp:GridView>
    </table>
    </div>
    </form>
</body>
</html>



 C# CODING

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



using System.Data;
using MySql.Data.MySqlClient;
public partial class Login : System.Web.UI.Page
{
    MySqlConnection con = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbc"].ToString());
     
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        MySqlCommand cmd = new MySqlCommand("sp_select_Date", con);

        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.AddWithValue("@vfromdate", txtDate.Text);
        cmd.Parameters.AddWithValue("@vusername",txtUsername.Text);

                    MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    adp.Fill(ds);
                    if(ds.Tables[0].Rows.Count>0)
                      {
                        GridView1.DataSource =ds;
                        GridView1.DataBind();
                        con.Close();
              }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        txtDate.Text = string.Empty;
        txtUsername.Text = string.Empty;
        GridView1.DataSource = null;
        GridView1.DataBind();
    }

}


 Add - New Web form - Required textbox and label and gridview add



Next - Cerate Mysql Stored Procedure for OR Query






Next - Add database and stored procedure in the Codebehind file 





What is AngularJS

AngularJS Tutorial

 AngularJs

AngularJs is a MVVM framework that help to create MVC and Single Page Applications (SPA) and use to developed dynamic web apps. AngularJS will be maintained and developed by Google Inc. AngularJs supported to MVVM and stands for Model-View-Whatever.

AngularJs is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. 


Basics of AngularJS

 Directives, Expressions, Filters, Modules, and Controllers.


AngularJS is an open source web application framework. It was originally developed in 2009 by Misko Hevery and Adam Abrons

It is now maintained by Google.

latest version is 1.4.8.



Advantages 



  • Model View Controller pattern,Less Coding,Two-way data binding,More Extensive User Interface,Template and Custom directive,Dynamic page Linking,Validations.

  • Core Features :
  • Data-binding
  • Controller
  • Services 
  • Scope 
  • Filters
  • Directives
  • Model View Controller
  • Dependency Injection
  • Deep Linking

The AngularJS Components


1.ng-app   - AngularJS application to HTML.

2.ng-modelAngularJS application data to HTML input controls.

3.ng-bind AngularJS Application data to HTML tags.


Use AngularJs

http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js


<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="your ng-app name">
 
<p> <input type="text" ng-model="your ng-modal"></p>
 
<h3>{{your ng-modal}}</h3>
</div>

</body>
</html>