Saturday 22 September 2012

Database operation ASP.net using SQL Server 2000


The ADO.NET architecture is designed to make life easier for both the application developer and the database provider. To the developer, it presents a set of abstract classes that define a common set of methods and properties that can be used to access any data source. The data source is treated as an abstract entity, much like a drawing surface is to the GDI+ classes.


Controls :
  • Three Textbox
  • Three Button
  • One GridView
  • SqlDataSource




Setting Gridview : 
  • Add Gridview select auto format if you want to use available style for gridview select a style click ok
  • Choose data source select < New Data source.. >
  • Select Database from Configuration Wizard 
  • Click New Connection and change database type from Add Connection wizard
  • Choose SQL Server click ok
  • Enter Server name I have have used . for local client server
  • Select Database Click ok
  • Select check your connection string and click next
  • Select your table and fields which you want to show on Gridview
Coding :
 SqlConnection con;
    SqlCommand com;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("initial catalog=bsw;data source=.;integrated security=true");
        com = com = new SqlCommand();
        com.Connection = con;
    }

Timer In ASP.Net Using AJAX

With the help of AJAX we can postback an specific  part of a web part.
Normally when we click on a control which has capability to postback its load entire
page which time and data consuming both.You can save your time and data cost both
With Ajax
Controls..

  • ScriptManager
  • UpdatePanel
  • Timer
  • Label
ASP Source code *.aspx


<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
            </asp:Timer>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
Server side code *.aspx.cs


public partial class _Default : System.Web.UI.Page
{
    static int i;
    
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        i++;
        Label1.Text = i.ToString();
    }
}

How to make search box on your web site


Google provide a custom search box which make you able to
search content on your website with the help of Google custom search box
just paste this code on your website where you want to place it...........

<form action="http://www.google.com/cse" id="cse-search-box" target="_self">
  <div>    
    <input type="hidden" name="ie" value="ISO-8859-1" />
    <input type="text" name="q" size="25" /><br />
    <input type="submit" name="sa" value="Search" class="formoutput"/>
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>

Friday 21 September 2012

Database Operation in Visual C#

Controls
  • Three TextBox
  • Three Button
  • One Data GridView


Setting DataGridView..
  • Click Datagridview task An Arrow right top side of Gridview
  • Choose Data Source
  • Add Project Data Source
  • Select Database from Configuration Wizard Click Next
  • Click New Connection Click change from add connection wizard,select Microsoft Access Database file from  change data source wizard click ok
  • Browse your database mdb file from your computer, Test Connection > Ok >click next from configuration wizard
  • Visual studio prompt you to add your database in current project if you want to add click yes otherwise on
  • Select table from configuratiob wizard select your table and check fields which you want show in Datagridview and finish




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace AccessDemo
{
    public partial class Form1 : Form
    {
        OleDbConnection con = new OleDbConnection(@"provider=microsoft.jet.oledb.4.0;data source=D:\Raj\c#\Database\bsw.mdb");
        OleDbCommand com = new OleDbCommand();
        public Form1()
        {
            try
            {
                con.Open();
                com.Connection = con;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtRoll.Text == "" || txtName.Text == "" || txtCity.Text == "")
            {
                MessageBox.Show("Please fill all field properly");
            }
            else
            {
                             
                try
                {
               
                    com.CommandText = "insert into stu values(" + txtRoll.Text + ",'" + txtName.Text + "','" + txtCity.Text + "')";
                    com.ExecuteNonQuery();
                    MessageBox.Show("saved");
                    this.stuTableAdapter.Fill(this.bswDataSet.stu);

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
         

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'bswDataSet.stu' table. You can move, or remove it, as needed.
            this.stuTableAdapter.Fill(this.bswDataSet.stu);

        }