How to insert records on disconnected mode in C#?

.......................................SOURCE ........................

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            background-color: #FF6699;
        }
        .style2
        {
            width: 33px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <table class="style1">
        <tr>
            <td class="style2">
                Name&nbsp;</td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                Password</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                Address</td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                <asp:GridView ID="GridView1" runat="server">
                </asp:GridView>
                <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
                <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Delete" />
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>
</html>
.............................code behind.........................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class dissconnectedmode : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
 
        }
    }
    SqlDataAdapter da;
    
    DataSet ds;
    DataTable dt;
    DataView dv;
    DataRow dr;
    

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = new DataTable();
            da = new SqlDataAdapter("select*from txtkul", con);
            da.Fill(dt);
             
          
                DataRow dr = dt.NewRow();
                dr[1]=TextBox1.Text;
                dr[2]=TextBox4.Text;
                dr[3]=TextBox3.Text;
                dt.Rows.Add(dr);
                SqlCommandBuilder cmb = new SqlCommandBuilder(da);
                da.Update(dt);
                Response.Write("<script>alert('Insert Successfully')</script>");


     
               
          
            GridView1.DataSource = dt;
            GridView1.DataBind();
                         
        }
        catch (Exception e1)
        {
            Response.Write(e1.Message);
        }



    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dt = new DataSet();
            da = new SqlDataAdapter("select*from txtkul", con);
            da.Fill(dt);
            for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
            {
                if (dt.Tables[0].Rows[i][1].ToString() == TextBox1.Text)
                {

                    dt.Tables[0].Rows[i][2] = TextBox4.Text;
                    dt.Tables[0].Rows[i][3] = TextBox3.Text;
                    
                    SqlCommandBuilder cmb = new SqlCommandBuilder(da);
                    da.Update(dt.Tables[0]);
                }
            }
            Response.Write("<script>alert('Insert Successfully')</script>");





            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
        catch (Exception e1)
        {
            Response.Write(e1.Message);
        }



    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlCommand cd = new SqlCommand();
        cd.CommandText = "select * from txtkul order by name";
        cd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cd);
        SqlCommandBuilder m_SQLCmdBuilder = new SqlCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds, "txtkul");
        
        int k = 1;
        int var = 0;

        for (var = 0; var < ds.Tables["txtkul"].Rows.Count; var++)
        {

            ds.Tables["txtkul"].Rows[var]["name"] = k;
            
            k++;

            da.Update(ds.Tables["txtkul"]);
           
        }
    }
}
            





  ...........................................end code behind................
Share:

No comments:

Post a Comment

Thursday, 3 January 2013

How to insert records on disconnected mode in C#?

.......................................SOURCE ........................

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            background-color: #FF6699;
        }
        .style2
        {
            width: 33px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <table class="style1">
        <tr>
            <td class="style2">
                Name&nbsp;</td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                Password</td>
            <td>
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                Address</td>
            <td>
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                <asp:GridView ID="GridView1" runat="server">
                </asp:GridView>
                <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
                <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Delete" />
            </td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>
</html>
.............................code behind.........................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class dissconnectedmode : System.Web.UI.Page
{

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
 
        }
    }
    SqlDataAdapter da;
    
    DataSet ds;
    DataTable dt;
    DataView dv;
    DataRow dr;
    

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = new DataTable();
            da = new SqlDataAdapter("select*from txtkul", con);
            da.Fill(dt);
             
          
                DataRow dr = dt.NewRow();
                dr[1]=TextBox1.Text;
                dr[2]=TextBox4.Text;
                dr[3]=TextBox3.Text;
                dt.Rows.Add(dr);
                SqlCommandBuilder cmb = new SqlCommandBuilder(da);
                da.Update(dt);
                Response.Write("<script>alert('Insert Successfully')</script>");


     
               
          
            GridView1.DataSource = dt;
            GridView1.DataBind();
                         
        }
        catch (Exception e1)
        {
            Response.Write(e1.Message);
        }



    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dt = new DataSet();
            da = new SqlDataAdapter("select*from txtkul", con);
            da.Fill(dt);
            for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
            {
                if (dt.Tables[0].Rows[i][1].ToString() == TextBox1.Text)
                {

                    dt.Tables[0].Rows[i][2] = TextBox4.Text;
                    dt.Tables[0].Rows[i][3] = TextBox3.Text;
                    
                    SqlCommandBuilder cmb = new SqlCommandBuilder(da);
                    da.Update(dt.Tables[0]);
                }
            }
            Response.Write("<script>alert('Insert Successfully')</script>");





            GridView1.DataSource = dt;
            GridView1.DataBind();

        }
        catch (Exception e1)
        {
            Response.Write(e1.Message);
        }



    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlCommand cd = new SqlCommand();
        cd.CommandText = "select * from txtkul order by name";
        cd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cd);
        SqlCommandBuilder m_SQLCmdBuilder = new SqlCommandBuilder(da);
        DataSet ds = new DataSet();
        da.Fill(ds, "txtkul");
        
        int k = 1;
        int var = 0;

        for (var = 0; var < ds.Tables["txtkul"].Rows.Count; var++)
        {

            ds.Tables["txtkul"].Rows[var]["name"] = k;
            
            k++;

            da.Update(ds.Tables["txtkul"]);
           
        }
    }
}
            





  ...........................................end code behind................

No comments:

Post a Comment

Popular

Total Pageviews

Archive