|
hai friends,
this is kishore,
i have one requirement importing data from excel to database, it should be done at server side
it is very urgent need
i could get succeed in exporting database to excel ,but iam unable to import excel to database
actually i have got the solution
but it is giving some problems, it is working only for one workbook(excel)
the code is below
'Getting a file path
If Not FILE1.PostedFile.FileName = "" Then
FilePath = FILE1.PostedFile.FileName
End If
'Excel Work Sheet Database Connection
MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & FilePath & "; " & _
"Extended Properties=Excel 8.0;")
'Select the data from Sheet1 of the workbook.
'FilePath comes as c:\export\mydata.xls
Dim f As Array
f = Split(FilePath, "\")
Dim k As Integer = f.Length
Dim str As String = f(k - 1)
Dim filename As String = str.Substring(0, str.LastIndexOf("."))
'' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
"select * from [" & filename & "$]", MyConnection)
DS = New System.Data.DataSet 'DataSet
MyCommand.Fill(DS) 'Filling The dataset
please help me, when iam going to export the data from database to excel, it is storing it as c1.xls(we give) and sheet1 name is also stored as c1.xls
when i am going to retrieve the data from it, it is giving an error
please help me
regards
kishore
|
|
|
|
|
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
|
|
|
|
|
hi all..
i have one problem with navigating between two pages. i have to open page2 from page1. and in page 2 i had to save some records and back to page1 immdiatley after saving. and while going back to page i need to show the records that r updated in page 2.. i have already some selected items in page 1. i donot want to reload the page..
history.back is not working for me.. i am using frames will history.back having any problem with frames??
redirecting page is reloading that page where the user selection is missing..
pls.. give me suggestion how can i solve this..
pls.. urgent ..
thanks..
|
|
|
|
|
Hi
For this u have to use self.close() javascript function for close popup page(page2).
Regards
RPL
r_palanivel83 10:01 4 Jan '06
|
|
|
|
|
hi,
I have used template columns (ItemTemplate and EditItemTemplate to display contents of gridview. it displays all the contents but i added extra commandbutton for edit as <asp:commandbutton headertext="edit" showeditbutton="true"> like this. but in runtime when i click edit link it displays error: Gridview Gridview1 not handled any rowediting event.
Please guide me how to add rowediting event and how to update the editions.
Thanks in advance,
Regards,
Prya
|
|
|
|
|
Prya, I have some code samples for you, just give me an email address so I can send the aspx page.
Nila
I do ANYTHING for an extra large cup of coffee!
|
|
|
|
|
Hi Nila,
My Email Id: sangeetha@visiontss.com
Regards,
Prya
|
|
|
|
|
Hi dears,
I have a web site with several master pages. and I used some user controls in my master pages, Now I can run and test website without any errors but when I want to publish website , an error occured for each user control used in master pages . the error is "circular file refrence are not allowed,Unknown server tag 'uc1:reminder' ". I have a little time to uploading website and dont know how to fix problem !!! plz help me...
www.behzadi.net
|
|
|
|
|
hi all
i m using grid view and i pick some value form grid in Gridview_selectedindex
whn i pick the value at Ist or IInd time tht pick correct value. but whn i click continuing into grid thn it shows a message/warning Stack OverFlow into 0 lines.
how can i resolve tht problem.
i hv some other codes into page load.
Deepak
Smile a Lots,Its Costs Nothing
|
|
|
|
|
This is usually due to some infinite recursion. Some piece of code is being called repeatedly from itself, or from something it calls.
|
|
|
|
|
thnx for help
so there is any proprites or method which clear my system stack.
Deepak
Smile a Lots,Its Costs Nothing
|
|
|
|
|
A stack, any stack, works on the prinicple of last on first off. To clear a stack you must remove the items in the reverse order in which they were placed.
In the case of the call stack of an application it means you have to continually return from methods without calling any new ones. Each time you return from a method the stack has less items on it. Each time you call a method the stack has more items on it.
Going back to your error. It looks like it is caused by infinite recursion. You must find where the recursion is getting out of control and fix it.
|
|
|
|
|
How can user change the size of column and row of gridview...
|
|
|
|
|
I have put following tags in web.config.
Aim is to grant access to users in "Administrators" role.But it is allowing all users wether Administrator or not.
<authentication mode="Windows" />
<authorization>
<allow roles="ServerName\Administrators" />
<deny users ="?"/>
</authorization>
Please help.
Thanks
|
|
|
|
|
You need to deny all users after allowing the Admin users to access, replace the ? with the * in the deny entry.
|
|
|
|
|
Thanks for reply.
i did the same but in this case it is not allowing anyone.
any idea?
|
|
|
|
|
Hi, I am using the following code to display the contents in gridview. but it displays only the headings not its contents. Please help me what i did wrongly.
Code .aspx Page
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Employee Id">
<ItemTemplate>
<asp:Label ID="lblEmployeeId" Text='<%Eval("EmployeeId")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:Label ID="lblLastName" Text='<%Eval("LastName")%>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:Label ID="lblFirstName" Text='<%Eval("FirstName") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:Label ID="lblTitle" Text='<%Eval("Title") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.aspx.cs Page
(created db connection to access and load query in data adapter and filled dataadapter into ds after that).
GridView2.DataSource = ds;
GridView2.DataBind();
Thanks in advance.
Regards,
Pryan data adapter and filled dataadapter into ds after that).
GridView2.DataSource = ds;
GridView2.DataBind();
Thanks in advance.
Regards,
<div class="ForumSig">Prya</div>
|
|
|
|
|
replace Text='<%Eval("fieldname")%>'
with
Text='<%#databinder.eval(container.dataItem,"fieldname")%>'
u will get the content on teh grid
yuvaraj
|
|
|
|
|
hi yuvaraj,
Thank u so much. Its working. But a small doubt for me, is when we have use Only Eval("fieldname") instead of #databinder.eval(container.dataitem,"fieldname").
Regards,
Prya
|
|
|
|
|
hi,
Thanks.
now gridview is displaying all the contents. and i added extra commandbutton for edit as <asp:CommandButton Headertext="edit" showeditbutton=true> like this. but in runtime when i click edit link it displays error: Gridview Gridview1 not handled any rowediting event.
Please guide me how to add rowediting event and how to update the editions.
Thanks in advance,
Regards,
Prya
|
|
|
|
|
iam using .net 2005 in atlas and iam getting problem for image uploading
regards
sunil
Sunil Tvl
|
|
|
|
|
And the problem is...?
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
that narrows it down.
It could be....
|
|
|
|
|
Hi All,
Can we send Query String to IFRAM page if yes then how.
|
|
|
|
|
Yes. Just include the querystring in the URL.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|