Friday 29 April 2016

Connection with SQL Server Part 7

Insert Data using Connection Class:-

on the submit button click event code for insert data using sql class connection

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 System.Data.SqlClient;

public partial class Insert : System.Web.UI.Page
{

    Class1 obj = new Class1();


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string str="insert into Datas(firstname,lastname,mobile) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"')";
        obj.savedata(str);
    }
}

In this coding the Class1 obj = new Class1();
 create new object of that class and we can use that class method , in our case we create two method the calldata(), and the savedata();

The calldata(); method is used to retrieve  data from database and 
  
The savadata(); method is used to execute the query

using the object of that class . 

Connection with SQL Server Part 6

SQLCommand

  • SqlCommand deals with databases. It executes SQL commands on a database. It sends an SQL command to a database that is specified by an SqlConnection object. We then call instance methods to physically apply the command to the database.

  • It is Responsible to execute SQL Query 
It is Required to Open Connection with the SqlCommand Class
using Open() Method and after, We Use the ExecuteNonQuery() method for Execute Query and after all we must close the connection using close() method

Connection with SQL Server Part 5

SQLDataAdapter

  • DataAdapter serves as a bridge between a DataSet and SQL Server for retrieving and saving data. We can use SqlDataAdapter Object in combination with Dataset Object. DataAdapter provides this combination by mapping Fill method, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet.


C#
  SqlDataAdapter adapter = new SqlDataAdapter(sql,connection );
adapter.Fill(ds);
  • The SqlDataAdapter Object and DataSet objects are combine to perform both data access and data manipulation operations in the SQL Server Database. When the user perform the SQL operations like Select , Insert etc. in the data containing in the Dataset Object , it wont directly affect the Database, until the user invoke the Update method in the SqlDataAdapter.
  • The DataAdapter can perform Select , Insert , Update and Delete SQL operations in the Data Source. The SelectCommand property of the DataAdapter is a Command Object that retrieves data from the data source. Other command properties of the DataAdapter are Command objects that manage updates to the data in the data source according to modifications made to the data in the DataSet.
  • The following ASP.NET program shows a select operation using SqlDataAdapter.

Connection with SQL Server Part 4

Dataset  Description:-

The DataSet contains DataTableCollection and theirDataRelationCollection . It represents a complete set of data including the tables that contain, order, and constrain the data, as well as the relationships between the tables.

We can use Dataset in combination with DataAdapter Class . Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter. The DataSet object offers a disconnected data source architecture. The following link gives you in details about Dataset Class with C# Source Code 


Properties



Initializes a new instance of the DataSet class.

System_CAPS_protmethodDataSet(SerializationInfo, StreamingContext)

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of a DataSet class that has the given serialization information and context.

System_CAPS_protmethodDataSet(SerializationInfo, StreamingContext, Boolean)

This API supports the product infrastructure and is not intended to be used directly from your code. Initializes a new instance of the DataSet class.

System_CAPS_pubmethodDataSet(String)
Initializes a new instance of a DataSet class with the given name.

Connection with SQL Server Part 3

The Connection String is used to Open Connection to the specified Sql Database

you can Copy it from Here
In Server Explore ,
Database Connection, You can see your Database

Right click on database and Click Properties


copy the connection string text:-
Past it to the con.connection string class Remove the C:etc\etc from Text And Fill Like this For Run Your application In Any Server

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|datadirectory|\\Database.mdf;Integrated Security=True;User Instance=True";
        

Connection with SQL Server Part 2

As You can see in code there are some header file which is added for connecting with the sql server

the header file
Using System.Data;
And
Using System.Data.SqlClient;
Is must required so don't forget it

Sqlconnection Description:-


SqlConnection()

Initializes a new instance of the SqlConnection class.

System_CAPS_pubmethodSqlConnection(String)

Initializes a new instance of the SqlConnection class when given a string that contains the connection string.

System_CAPS_pubmethodSqlConnection(String, SqlCredential)

Initializes a new instance of the SqlConnection class given a connection string, that does not useIntegrated Security = true and a SqlCredential object that contains the user ID and password.


Connection with SQL Server Part 1


In Add New Item Select Class And Language C#

Code for it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Class2
/// </summary>
public class Class2
{
    SqlConnection con = new SqlConnection();
public Class2()
{

        con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|datadirectory|\\Database.mdf;Integrated Security=True;User Instance=True";
        
}
    public DataSet calldata(string str)
    {
        SqlDataAdapter adp = new SqlDataAdapter(str, con);
        DataSet ds = new DataSet();
        adp.Fill(ds);
        return ds;
    }
    public void savedata(string str)
    {
        SqlCommand cmd = new SqlCommand(str,con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

}

Friday 1 April 2016

SQL Server CRUD Insert

Step 4 :

In Server Explore Right Click on Your Database , After it Right Click at Table Add New TableAdd column in table And Save it with table's name



SQL Server CRUD Insert

Step 3 :

New Window will prompt Press Yes to save Database in App_Data Folder :

Press Yes

SQL Server CRUD Insert

Step 2 :


Select SQL Server Database And Give it your Database Name :

Select SQL Server Database And Give it your Database Name

SQL Server CRUD Insert

Create Database :-

To Create Database in C# Following Screen Shot Will Help you

Step 1 :

Right Click on your project Add New Item..

Basic Of C#

Do While Loop :-

coding :

 protected void Page_Load(object sender, EventArgs e)
    {
        int n = 1;
        do
        {
            Response.Write(n + "Welcome<br>");
            n++;
        }
        while (n <= 15);
        
    }

So This all are Basic of the C# Programming you can use according to your requirement

if you Like it Please Like , SHARE & COMMENTS

Basic Of C#

Do While Loop :-

coding :

 protected void Page_Load(object sender, EventArgs e)
    {
        int n = 1;
        do
        {
            Response.Write(n + "Welcome<br>");
            n++;
        }
        while (n <= 15);
        
    }

Basic Of C#

For Loop :

Coding:- 

protected void Page_Load(object sender, EventArgs e)
    {
        for (int n = 1; n <= 10; n++)
        {
            Response.Write(n+"for loop<br>");
        }
    }


While Loop :

Coding :-

 protected void Page_Load(object sender, EventArgs e)
    {
        int n = 1;
        while (n <= 15)
        {
            Response.Write(n + "hello<br>");
            n++;
        }
        
    }

Basic Of C#

Variable in C# :

  • A variable represents a numeric or string value or an object of a class. The value that the variable stores may change, but the name stays the same. A variable is one type of field. The following code is a simple example of how to declare an integer variable, assign it a value, and then assign it a new value.
  • int x = 15;  // x holds the value 15
    x = 7;      // now x holds the value 7
string words = "Hello, World!";
Response.write(words);

Conditional Statement :

In conditional statementsconditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false

If - Else Statement Coding;

protected void Page_Load(object sender, EventArgs e)
 { 
           string str = "hellow";
           if (str == "hellowe") 
                    { 
                  Response.Write("yes"); } else { Response.Write("No");
                     } 
 }

Tuesday 22 March 2016

All About ASP.NET

ASP.NET

  •  Ii is an open-source server-side web application framework designed for web development to produce dynamic web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services

  • It provides better performance by taking advantage of early binding, just-in-time compilation, native optimization, and caching services right out of the box.

  •  It is purely server-side technology so, ASP.NET code executes on the server before it is sent to the browser

  • Better Security

  • Object-oriented

Part 20 consuming rest api in ionic

in this video, I will show you that how you can consume the rest API. in the previous video we have implemented the asp.net web API projec...