What is the difference between Server.Transfer and
Response.Redirect? Why would you choose one over the other?
Answers were Sorted based on User's Feedback
Answer / q
StreamReader sr = new StreamReader(@"C:/Documents and
Settings/232838/Desktop/Sample1.txt");
string test = sr.ReadToEnd().Replace("<", "<").Replace
(">", ">");
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / xy
Set exCon = Server.CreateObject( "ADODB.Connection" )
Set dbCon = Server.CreateObject
( "ADODB.Connection" )
'open connection to excel
'had to use the JET driver since some of
the ODBC functionality didnt work
exCon.ConnectionTimeout = 30
' exCon.open "Driver={Microsoft Excel Driver
(*.xls)};Dbq=" & Filepath & ";UID=admin;TypeGuessRows=0;"
exCon.open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Filepath & ";Extended Properties=""Excel
8.0;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0"""
exCon.CommandTimeout = 90
'open connection to DB
openDBConnection(dbCon)
set rs=exCon.OpenSchema(20)
strPageName = rs(2)
'ADO replaces a ' with a '' by default. we
need to undo this change during the import.
if instr(strPageName, "''") > 0 then
response.write "The name of the
Spreadsheet tab cannot have a comma. "
response.write "The current name
["& replace(strPageName,"''","'") &"] must be corrected
before it can be uploaded.<BR>"
response.End()
end if
response.write "Page <B>" & strPagename
& "</B> was imported"
rs.close
set rs=nothing
Set RS = Server.CreateObject
("ADODB.Recordset")
RS.ActiveConnection = exCon
RS.CursorType =
1
RS.LockType =
1
RS.Source = "SELECT * FROM [" &
strPageName & "] where siteno is not null and projcode = '"
& strProjCode & "'"
RS.Open
if not rs.eof then
arrData = rs.getrows()
else
response.redirect "/error.asp?msg=Template Projcode
Mismatch ! (" & Request.ServerVariables("URL") & ")"
response.end
end if
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / d
using System.Data.OleDb;
string strFilePath = @"D:\Development\Test.xlsx";
try {
string strConnectionString = string.Empty;
//strConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
strFilePath + @";Extended Properties=""Excel
8.0;HDR=YES;IMEX=1""";
strConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
strFilePath + @";Extended Properties=""Excel 12.0
Xml;HDR=YES;IMEX=1""";
OleDbConnection cnCSV = new OleDbConnection
(strConnectionString);
cnCSV.Open();
OleDbCommand cmdSelect = new OleDbCommand
(@"SELECT * FROM [Sheet1$]", cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter();
daCSV.SelectCommand = cmdSelect;
DataTable dtCSV = new DataTable();
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
Response.Write(dtCSV.Rows.Count);
gvTest.DataSource = dtCSV;
gvTest.DataBind();
} catch (Exception ex) {
} finally {
}
<asp:GridView ID="gvTest" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="GDCID" DataField="GDCID" />
<asp:BoundField HeaderText="EmpID" DataField="EmpID" />
</Columns>
</asp:GridView>
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / d
Put it inside <configuration> section
<connectionStrings>
<add key="conString" value="server=01HW154261\SQLEXPRESS;
database=MyDB; user id=; password=;" />
</connectionStrings>
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.AppSettings
["conString"].ToString();
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter("Select a.State
From State as a inner join Country as b on a.CountryID =
b.CountryID where b.CountryID = " + countryID, con);
DataSet dstCountry = new DataSet();
adapter.Fill(dstCountry);
con.Close();
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / x
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public string qry = string.Empty;
public SqlDataAdapter dap = null;
public DataSet dst = null;
public string proj;
public string mod;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString =
ConfigurationManager.ConnectionStrings
["Connection"].ToString();
con.Open();
string sql = string.Empty;
string projCode = string.Empty;
string moduleID = string.Empty;
if (!IsPostBack)
{
qry = "Select Projcode from Etmtech.dbo.Project
where edgesupported = 1 and libraryname = 'recon' order by
projcode";
dap = new SqlDataAdapter(qry, con);
dst = new DataSet();
dap.Fill(dst);
selProject.DataSource = dst;
selProject.DataTextField = dst.Tables[0].Columns
["Projcode"].ToString().ToUpper();
selProject.DataBind();
dap.Dispose();
dst.Dispose();
qry = "Select clientname,clientid from
etmtech.dbo.client (nolock) order by clientid";
dap = new SqlDataAdapter(qry, con);
dst = new DataSet();
dap.Fill(dst);
selClient.DataSource = dst;
selClient.DataTextField = dst.Tables[0].Columns
["clientname"].ToString();
selClient.DataValueField = dst.Tables[0].Columns
["clientid"].ToString();
selClient.DataBind();
dap.Dispose();
dst.Dispose();
}
projCode = selProject.SelectedValue.ToString();
if(Session["projCode"] == null || !projCode.Equals
(Session["projCode"].ToString()))
{
qry = string.Empty;
qry = "Select descr,moduleid from
Recon.dbo.Recon_Menu (Nolock) where projcode = '" +
selProject.SelectedItem.Text + "'";
dap = new SqlDataAdapter(qry, con);
dst = new DataSet();
dap.Fill(dst);
selModule.DataSource = dst;
selModule.DataValueField = dst.Tables[0].Columns
["moduleid"].ToString();
selModule.DataTextField = dst.Tables[0].Columns
["descr"].ToString();
selModule.DataBind();
dap.Dispose();
dst.Dispose();
Session["projCode"] = projCode;
}
moduleID = selModule.SelectedValue;
if (!moduleID.Equals(string.Empty))
{
qry = string.Empty;
qry = "select
o.objectorder,o.descr,pt.name,p.parmvalue from
recon.dbo.recon_object o (nolock)";
qry = qry + " ,recon.dbo.recon_parameter p
(nolock),recon.dbo.recon_lu_parametertype pt (nolock)";
qry = qry + " where o.moduleid =" +
Convert.ToInt32(moduleID) + " and o.objectid = p.objectid
and p.parmtypeid = pt.parmtypeid order by o.objectorder";
dap = new SqlDataAdapter(qry, con);
dst = new DataSet();
dap.Fill(dst);
GVobj.DataSource = dst;
GVobj.DataBind();
if (dst.Tables[0].Rows.Count > 0)
{
btSave.Enabled = true;
btCancel.Enabled = true;
}
dap.Dispose();
dst.Dispose();
}
string client = selClient.SelectedValue.ToString();
}
protected void GVobj_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 0)
{
proj = e.Row.Cells[1].Text;
}
if (e.Row.RowIndex > 0)
{
if (proj.Equals(e.Row.Cells[1].Text))
{
e.Row.Cells[1].Text = "";
}
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / x
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public SqlDataAdapter dap = null;
public DataSet dst = null;
public string projDesc = string.Empty;
public string divisionName = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString =
ConfigurationManager.ConnectionStrings["conString"].ToString
();
con.Open();
string sql = string.Empty;
string projCode = string.Empty;
string divisionCode = string.Empty;
if (!IsPostBack)
{
dap = new SqlDataAdapter("select * from
Project", con);
dst = new DataSet();
dap.Fill(dst);
ddlProject.DataSource = dst;
ddlProject.DataValueField = dst.Tables
[0].Columns["ProjCode"].ToString();
ddlProject.DataTextField = dst.Tables[0].Columns
["ProjDesc"].ToString();
ddlProject.DataBind();
dap.Dispose();
dst.Dispose();
}
projCode = ddlProject.SelectedValue.ToString();
if (Session["projCode"] == null || !projCode.Equals
(Session["projCode"].ToString()))
{
sql = "select * from Division where ProjCode
= " + Convert.ToInt32(projCode);
dap = new SqlDataAdapter(sql, con);
dst = new DataSet();
dap.Fill(dst);
ddlDivision.DataSource = dst;
ddlDivision.DataValueField = dst.Tables
[0].Columns["DivisionID"].ToString();
ddlDivision.DataTextField = dst.Tables
[0].Columns["DivisionName"].ToString();
ddlDivision.DataBind();
dap.Dispose();
dst.Dispose();
Session["projCode"] = projCode;
}
divisionCode = ddlDivision.SelectedValue.ToString();
if (!divisionCode.Equals(string.Empty))
{
sql = "select a.ProjDesc, b.DivisionName,
c.MemberName from Project a inner join Division b on
a.ProjCode = b.ProjCode ";
sql += "inner join Member c on b.DivisionID =
c.DivisionID where a.ProjCode = " + Convert.ToInt32
(projCode);
sql += " and b.DivisionID = " + Convert.ToInt32
(divisionCode);
dap = new SqlDataAdapter(sql, con);
dst = new DataSet();
dap.Fill(dst);
gvProj.DataSource = dst;
gvProj.DataBind();
dap.Dispose();
dst.Dispose();
}
con.Close();
}
protected void gvProj_RowDataBound(object sender,
GridViewRowEventArgs e)
{
gvRowCheck(e);
}
private void gvRowCheck(GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 0)
{
projDesc = e.Row.Cells[0].Text;
divisionName = e.Row.Cells[1].Text;
}
if (e.Row.RowIndex > 0)
{
if (projDesc.Equals(e.Row.Cells[0].Text))
{
e.Row.Cells[0].Text = "";
}
if (divisionName.Equals(e.Row.Cells[1].Text))
{
e.Row.Cells[1].Text = "";
}
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / d
/* Default.aspx */
<div>
<asp:DropDownList ID="ddlProject" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:DropDownList ID="ddlDivision" runat="server"
AutoPostBack="true"></asp:DropDownList>
<asp:GridView ID="gvMember" runat="server"
AutoGenerateColumns="false"
OnRowDataBound="gvMember_RowDataBound">
<Columns>
<asp:BoundField DataField="ProjDesc"
HeaderText="Project Name" />
<asp:BoundField DataField="DivisionName"
HeaderText="Division Name" />
<asp:BoundField DataField="MemberID" HeaderText="Member
ID" />
<asp:BoundField DataField="MemberName"
HeaderText="Member Name" />
</Columns>
</asp:GridView>
</div>
/* Default.aspx.cs */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public string projDesc = string.Empty;
public string divisionName = string.Empty;
protected void Page_Load(object sender, EventArgs e) {
string projCode = string.Empty;
string divisionID = string.Empty;
if (!IsPostBack) {
PopulateData.LoadProject(ddlProject);
}
projCode = ddlProject.SelectedValue.ToString();
if (Session["projCode"] == null || !projCode.Equals
(Session["projCode"].ToString())) {
PopulateData.LoadDivision(ddlDivision,
projCode);
Session["projCode"] = projCode;
}
divisionID = ddlDivision.SelectedValue.ToString();
if (!divisionID.Equals(string.Empty)) {
gvMember.DataSource =
PopulateData.LoadMemberDetails(projCode, divisionID);
gvMember.DataBind();
}
}
protected void gvMember_RowDataBound(object sender,
GridViewRowEventArgs e) {
if (e.Row.RowIndex == 0) {
projDesc = e.Row.Cells[0].Text;
divisionName = e.Row.Cells[1].Text;
}
if (e.Row.RowIndex > 0) {
if (projDesc.Equals(e.Row.Cells[0].Text)) {
e.Row.Cells[0].Text = "";
}
if (divisionName.Equals(e.Row.Cells[1].Text)) {
e.Row.Cells[1].Text = "";
}
}
}
}
/* Populate.cs */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for PopulateData
/// </summary>
public class PopulateData
{
public PopulateData()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet LoadProject() {
string query = string.Empty;
query = "select * from Project";
DataSet dst = Data.getDataSet(query);
return dst;
}
public static void LoadProject(DropDownList ddlProject)
{
string query = string.Empty;
query = "select * from Project";
DataSet dst = Data.getDataSet(query);
ddlProject.DataSource = dst;
ddlProject.DataValueField = dst.Tables[0].Columns
["ProjCode"].ToString();
ddlProject.DataTextField = dst.Tables[0].Columns
["ProjDesc"].ToString();
ddlProject.DataBind();
dst.Dispose();
}
public static DataSet LoadDivision(string projCode) {
string query = string.Empty;
query = "select * from Division where ProjCode = "
+ Convert.ToInt32(projCode);
DataSet dst = Data.getDataSet(query);
return dst;
}
public static void LoadDivision(DropDownList
ddlDivision, string projCode) {
string query = string.Empty;
query = "select * from Division where ProjCode = "
+ Convert.ToInt32(projCode);
DataSet dst = Data.getDataSet(query);
ddlDivision.DataSource = dst;
ddlDivision.DataValueField = dst.Tables[0].Columns
["DivisionID"].ToString();
ddlDivision.DataTextField = dst.Tables[0].Columns
["DivisionName"].ToString();
ddlDivision.DataBind();
dst.Dispose();
}
public static DataSet LoadMemberDetails(string
projCode, string divisionID) {
string query = string.Empty;
query = "select c.ProjDesc, b.DivisionName,
a.MemberID, a.MemberName from Member a";
query += " inner join Division b on a.DivisionID =
b.DivisionID";
query += " inner join Project c on b.ProjCode=
c.ProjCode";
query += " where a.ProjCode = " + Convert.ToInt32
(projCode) + " and a.DivisionID = " + Convert.ToInt32
(divisionID);
DataSet dst = Data.getDataSet(query);
return dst;
}
}
/* Connection.cs */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Connection
/// </summary>
public class Connection
{
public Connection()
{
//
// TODO: Add constructor logic here
//
}
public static SqlConnection OpenConnection
(SqlConnection con) {
con.ConnectionString =
ConfigurationManager.ConnectionStrings["conString"].ToString
();
con.Open();
return con;
}
public static void CloseConnection(SqlConnection con){
if (con.State == ConnectionState.Open) {
con.Close();
}
}
}
/* Data.cs */
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Summary description for Data
/// </summary>
public class Data
{
public Data()
{
//
// TODO: Add constructor logic here
//
}
public static DataSet getDataSet(string query) {
SqlConnection con = new SqlConnection();
DataSet dst = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(query,
Connection.OpenConnection(con));
dap.Fill(dst);
Connection.CloseConnection(con);
return dst;
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / s
http://www.codeproject.com/KB/webforms/NingLiangSimpleContro
l.aspx
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rao
server.transfer is transfer to with in the application
pages.but responce.redirect can transfer to any page.
ex
response.redirect("www.google.com");
it is not work for server.transfer.
| Is This Answer Correct ? | 0 Yes | 0 No |
i need code for insert,delete,update adn display records using stored procedure in C#
Difference between ASP & ASP.NET Session State
How can we create Tree control in asp.net?
What are the various session state management options provided by asp.net?
what is Satellite Assembly?
Which method is used to force all the validation controls to run?
What is meant by server side scripting?
What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
relacement of websevices in .net 3.0?
What is the concept of view state in asp.net?
what is the cursor
How does exception management works in ASP.NET?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)