Click here to Skip to main content
15,890,185 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionMove Records Up/ Down in Datagrid Pin
wEb GuRu...13-Dec-06 2:01
wEb GuRu...13-Dec-06 2:01 
AnswerRe: Move Records Up/ Down in Datagrid Pin
Not Active13-Dec-06 2:59
mentorNot Active13-Dec-06 2:59 
Questionweb.config settings problem [modified] Pin
R.Palanivel13-Dec-06 1:54
R.Palanivel13-Dec-06 1:54 
AnswerRe: web.config settings problem Pin
Pete O'Hanlon13-Dec-06 2:25
mvePete O'Hanlon13-Dec-06 2:25 
GeneralRe: web.config settings problem Pin
R.Palanivel13-Dec-06 19:05
R.Palanivel13-Dec-06 19:05 
GeneralRe: web.config settings problem Pin
Pete O'Hanlon13-Dec-06 22:54
mvePete O'Hanlon13-Dec-06 22:54 
QuestionCan u Please help me in Importing data excel to database in asp.net(vb.net) Pin
kishore19@hotmail.com13-Dec-06 1:16
kishore19@hotmail.com13-Dec-06 1:16 
Questionupdate database using dataset need help!!! Pin
Dinuraj13-Dec-06 1:12
Dinuraj13-Dec-06 1:12 
Hi,
I am trying to bulk update database using dataset.I think so i have to pass update sql statement but i dont have idea. Can anyone hepl me...
i am sending aspa page code as well code behind..
Please send me code not description....

<%@ Page language="c#" Codebehind="DataSetTest.aspx.cs" AutoEventWireup="false" Inherits="RnD.DataSetTest" %>



<title>DataSetTest







<asp:datagrid id="grdEmployee" style="Z-INDEX: 101; LEFT: 10px; POSITION: absolute; TOP: 105px" runat="server" onupdatecommand="grdEmployee_Update" oncancelcommand="grdEmployee_Cancel" oneditcommand="grdEmployee_Edit" onpageindexchanged="Grid_Change" pagesize="10" allowpaging="True" onsortcommand="Sort_Grid" allowsorting="True" backcolor="#ccff66" datakeyfield="ID" autogeneratecolumns="False">
<headerstyle font-bold="True" backcolor="#ccccff">
<alternatingitemstyle backcolor="#ccffff">
<selecteditemstyle backcolor="#ff00ff">
<columns>
<asp:boundcolumn datafield="NAME" headertext="NAME" sortexpression="NAME">
<asp:boundcolumn datafield="DESIGNATION" headertext="DESIGNATION" sortexpression="DESIGNATION">
<asp:boundcolumn datafield="SEX" headertext="SEX" sortexpression="SEX">
<asp:boundcolumn datafield="AGE" headertext="AGE" sortexpression="AGE">
<asp:boundcolumn datafield="SALARY" headertext="SALARY" sortexpression="SALARY">
<asp:editcommandcolumn buttontype="LinkButton" edittext="Edit" headertext="Edit Command" canceltext="Cancel" updatetext="Update">


<asp:button id="btnDatabaseUpdate" style="Z-INDEX: 102; LEFT: 19px; POSITION: absolute; TOP: 15px" runat="server" text="Update on Database">



Code Behind:--

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace RnD
{
///
/// Summary description for DataSetTest.
///

public class DataSetTest : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid grdEmployee;
protected System.Web.UI.WebControls.Button btnDatabaseUpdate;
DataSet dsObj=new DataSet();
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
try
{
string strConnection= System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
//Response.Write(strConnection);
SqlConnection con = new SqlConnection();
con.ConnectionString = strConnection;
SqlCommand cmd=new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_GetEMPLOYEEDETAILS";
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dsObj,"EMPLOYEEDETAILS");
grdEmployee.DataSource= dsObj;
grdEmployee.DataBind();
Cache["EMPCACHE"]=dsObj;
dsObj = null;
cmd.Connection.Close();
}
catch (Exception ex)
{
Response.Write("
" + ex.Message.ToString());
this.RegisterStartupScript("Dialog",@"alert('Error In Connection')");
}
}

}
public void Sort_Grid(Object o,DataGridSortCommandEventArgs e)
{
if (Cache["EMPCACHE"]!=null)
{
DataSet dsSort= (DataSet)Cache["EMPCACHE"];
DataView dv = new DataView(dsSort.Tables[0]);
dv.Sort = e.SortExpression;
grdEmployee.DataSource = dv;
grdEmployee.DataBind();
dsSort = null;
}

}

public void Grid_Change(Object o,DataGridPageChangedEventArgs e)
{
if (Cache["EMPCACHE"]!=null)
{
DataSet dsSort= (DataSet)Cache["EMPCACHE"];
DataView dv = new DataView(dsSort.Tables[0]);
grdEmployee.CurrentPageIndex = e.NewPageIndex;
grdEmployee.DataSource = dv;
grdEmployee.DataBind();
dsSort = null;
}

}

public void grdEmployee_Edit(Object o,DataGridCommandEventArgs e)
{
grdEmployee.EditItemIndex = e.Item.ItemIndex ;
if (Cache["EMPCACHE"]!=null)
{
DataSet dsSort= (DataSet)Cache["EMPCACHE"];
DataView dv = new DataView(dsSort.Tables[0]);
grdEmployee.DataSource = dv;
grdEmployee.DataBind();
dsSort = null;
}
}

public void grdEmployee_Cancel(Object o,DataGridCommandEventArgs e)
{
grdEmployee.EditItemIndex = -1 ;
//grdEmployee.EditItemIndex = e.Item.ItemIndex ;
if (Cache["EMPCACHE"]!=null)
{
DataSet dsSort= (DataSet)Cache["EMPCACHE"];
DataView dv = new DataView(dsSort.Tables[0]);
grdEmployee.DataSource = dv;
grdEmployee.DataBind();
dsSort = null;
}
}

public void grdEmployee_Update(Object o,DataGridCommandEventArgs e)
{
int id = (int)grdEmployee.DataKeys[e.Item.ItemIndex];
//Response.Write(id);

TextBox txtName,txtDesignation,txtSex,txtAge,txtSalary;
txtName =(TextBox)e.Item.Cells[0].Controls[0];
txtDesignation =(TextBox)e.Item.Cells[1].Controls[0];
txtSex =(TextBox)e.Item.Cells[2].Controls[0];
txtAge =(TextBox)e.Item.Cells[3].Controls[0];
txtSalary =(TextBox)e.Item.Cells[4].Controls[0];
if (Cache["EMPCACHE"]!=null)
{
DataSet dsUpdate= (DataSet)Cache["EMPCACHE"];
dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["NAME"]=txtName.Text;
dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["DESIGNATION"]=txtDesignation.Text;
dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SEX"]=txtSex.Text;
dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["AGE"]=Convert.ToInt32(txtAge.Text);
dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SALARY"]=Convert.ToSingle(txtSalary.Text);

//dsUpdate.AcceptChanges();
Cache["EMPCACHE"]=dsUpdate;
grdEmployee.EditItemIndex = -1 ;
grdEmployee.DataSource = dsUpdate;
grdEmployee.DataBind();

dsUpdate=null;
}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.btnDatabaseUpdate.Click += new System.EventHandler(this.btnDatabaseUpdate_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnDatabaseUpdate_Click(object sender, System.EventArgs e)
{

try
{
string strConnection= System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
//Response.Write(strConnection);
SqlConnection con = new SqlConnection();
con.ConnectionString = strConnection;
SqlDataAdapter sda = new SqlDataAdapter("select ID,NAME,DESIGNATION,SEX,AGE,SALARY from EMPLOYEEDETAILS",con);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);

//con.Open();
sda.Fill(dsObj,"EMPLOYEEDETAILS");


DataSet dsUpdate = (DataSet)Cache["EMPCACHE"];
//dsUpdate.AcceptChanges();
dsObj = dsUpdate.Copy();

//sda.UpdateCommand = scb.GetUpdateCommand();
int success=sda.Update(dsObj,"EMPLOYEEDETAILS");
//con.Close();
dsObj.AcceptChanges();
Response.Write(success);
grdEmployee.DataSource = dsObj;
grdEmployee.DataBind();
}
catch (Exception ex)
{
Response.Write("
" + ex.Message.ToString());
this.RegisterStartupScript("Dialog",@"alert('Error In Connection')");
}

}
}
}


looking forward for prompt response
Questionnavigation/popup Pin
Smiles7412-Dec-06 23:39
Smiles7412-Dec-06 23:39 
AnswerRe: navigation/popup Pin
R.Palanivel13-Dec-06 1:59
R.Palanivel13-Dec-06 1:59 
QuestionGridView Pin
aaraaayen12-Dec-06 22:59
aaraaayen12-Dec-06 22:59 
AnswerRe: GridView Pin
Grapes-R-Fun13-Dec-06 10:01
Grapes-R-Fun13-Dec-06 10:01 
GeneralRe: GridView Pin
aaraaayen13-Dec-06 17:44
aaraaayen13-Dec-06 17:44 
QuestionPlease Help Me for User Controls... Pin
amin_behzadi12-Dec-06 22:39
professionalamin_behzadi12-Dec-06 22:39 
Questionproblem about Stack Pin
Deepak the Cool12-Dec-06 22:33
Deepak the Cool12-Dec-06 22:33 
AnswerRe: problem about Stack Pin
Colin Angus Mackay12-Dec-06 22:38
Colin Angus Mackay12-Dec-06 22:38 
GeneralRe: problem about Stack Pin
Deepak the Cool12-Dec-06 22:49
Deepak the Cool12-Dec-06 22:49 
GeneralRe: problem about Stack Pin
Colin Angus Mackay13-Dec-06 0:52
Colin Angus Mackay13-Dec-06 0:52 
QuestionChange column and row size of gridviw Pin
Animesh Dadheech12-Dec-06 21:38
Animesh Dadheech12-Dec-06 21:38 
QuestionASP.NET Windows Authentication Pin
payback12-Dec-06 20:29
payback12-Dec-06 20:29 
AnswerRe: ASP.NET Windows Authentication Pin
minhpc_bk13-Dec-06 0:29
minhpc_bk13-Dec-06 0:29 
GeneralRe: ASP.NET Windows Authentication Pin
payback13-Dec-06 19:38
payback13-Dec-06 19:38 
QuestionGridview [modified] Pin
aaraaayen12-Dec-06 19:05
aaraaayen12-Dec-06 19:05 
AnswerRe: Gridview Pin
yuvachandra12-Dec-06 19:58
yuvachandra12-Dec-06 19:58 
GeneralRe: Gridview Pin
aaraaayen12-Dec-06 20:05
aaraaayen12-Dec-06 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.