Hi, try this. string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strfilename + ";Extended Properties=Excel 8.0;"; OleDbConnection mycon = new OleDbConnection(strConn); try { //Get the data from selected excel sheet. OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM ["+lstEmpSheets.SelectedValue+"]", strConn); if (mycon.State != ConnectionState.Open) //if connection is not open, open it mycon.Open(); //DataSet myDataSet = new DataSet(); myCommand.Fill(dt); mycon.Close(); } catch(Exception ex) { lblResult.Visible = true; lblResult.Text = ex.Message.ToString(); } finally { if (mycon.State == ConnectionState.Open) //if connection is not open, open it mycon.Close(); } try { if(dt!=null) { con = new SqlConnection((string) ConfigurationSettings.AppSettings["ConnectionString"]); con.Open(); cmd = new SqlCommand(); cmd.Connection=con; //Get the data from data table and update the database. foreach(DataRow dr in dt.Rows) { //Need to write relative code here. string empId = dr[0].ToString().Trim(); errRefEmp =empId; string name = dr[1].ToString().Trim(); string project = dr[2].ToString().Trim(); string supervisor= dr[3].ToString().Trim(); string mailId= dr[4].ToString().Trim(); if((empId.CompareTo("")==0)||(supervisor.CompareTo("")==0)|| string query = " INSERT INTO EMPLOYEE "; query += " VALUES ('"+empId+"','"+name+"','"+project+"','"+supervisor+"','"+mailId+"')"; cmd.CommandText=query; cmd.ExecuteNonQuery(); con.Close(); Page.RegisterStartupScript("SuccessfulEmpUpdation","alert('Excel file uploaded Successfully.!')"); Thanks and regards Gowtham sen
Gowtham Sen
Posts
-
Import Excel into Sql Database -
Export dataset to excel file on a disk driveHi, follow this link. This is the article submitted by me, which describes about ur requirement. http://www.dotnetspider.com/kb/Article1848.aspx Thanks and Regards Gowtham Sen
-
How can I pass Dataset from one page to another?Hi, You can do this using session variables. After creating a dataset Session["dataset}]= dataset --------- while accessing DataSet ds = (DataSet)(Session["dataset"]); Thanks and Regards Gowtham Sen
-
[Message Deleted]Hi, Send a success message as a query string to the redirected url. There access the query string and display a message box. Try as follows. Response.Redirect("yourform.aspx?result=success"); ------------- In yourform.aspx string result = Request.QueryString["result"]; Page.RegisterStartupScript("result","alert('"+result+"')")------- Thanks and Regards Gowtham Sen.
-
How to track the pages visited?Dear expers, While generally, we visited pages,and we do back and forward to those pages which are already visited. How can we do this using asp.net with C#. Its an urgent requirement for my application. How can I do this? Could you please help me. Thanks and Regards Gowtham Sen.
-
variable passing by URLhi, when you redirecting to a page, just add the query string with the url as follows. Response.Redirect("yourRedirectedForm.aspx?url=linktoform.aspx"); Then at the page YourRedirectedForm.aspx access the querystring as follows. string url = Request.QeryString["url}]; Response.Redirect(url); In this way you can do this. Thanks and Regards Gowtham Sen.
-
How can I update data on web page (already opened) when another user updates data in database.Hi, You can do this, by refreshing the page. You can do automatic refresh for a particular period of time. Just add the following tag. For the above tag, the page will be refreshed for every 100 seconds. Thanks and Regards Gowtham Sen.
-
How to change the url while refreshing?Hi, Thanks a lot. What exactly my problem is, I am sending a messge as a query string with an url. There I am checking any message with the url by evaluation querystring.count. While the count is greater than 0 then I am displaying the message using Page.RegisterStartupScript(). It should be done only once I open the page. So I added in the if loop where the page is not postbacked. Its all working good. But the problem is, I am refresshing the page automatically for certain period of time. I did well. But the problem, is the querystring still in the url. So whenever the page is refreshed, I am getting the message again. If I did as you said, Response.Redirect(), then I am not getting the message. How can I do this? Could you please help me. Thanks and Regards Gowtham Sen
-
How to change the frame source(src) dynamically.?..!urgentThanks a lot my friend. But as you said I added runat="server". Then I am getting an error message as Page cannot be found. If I removed that, its working good. And another thing is, while I am debugging, the control is not going to dynamichelp.aspx.c file. How can I do this? Thanks and Regards Gowtham Sen.
-
How to change the frame source(src) dynamically.?..!urgentHey, Thanks a lot. My page code is as follows. <%@ Page language="c#" Codebehind="dynamichelp.aspx.cs" AutoEventWireup="false" Inherits="RequestLaptop.dynamichelp" %> dynamic help
Here in the above I underline the frame, where I want to change source dynamically. In the above the frame help_display, where I would like to change the source dynamically. How can I do this. As you said, where do I add the code? Thanks and Regards Gowtham Sen.
-
How to change the url while refreshing?Dear Expers. I have one doubt regarding page refreshing. I am sending querystring to page(say p1). While I am redirected to the page(p1), I am displaying a messagebox with query string values. I am refreshing my page for every 1 minute. But the query string is remains in the url. So every time I refresh the page, I am getting the message box. I want the message box only once. Not every time. How can I do this? Could you please help me? Thanks and Regards Gowtham
-
Refresh funtion in webapplicationHi HimaBindu, Its a right answer. I have one doubt regarding this. I am sending querystring to page(say p1). While I am redirected to the page(p1), I am displaying a messagebox with query string values. As you said , I am refreshing my page for every 1 minute. But the query string is remains in the url. So every time I refresh the page, I am getting the message box. I want the message box only once. Not every time. How can I do this? Could you please help me? Thanks and Regards Gowtham
-
How to change the frame source(src) dynamically.?..!urgentDear Experts, I have a problem with frame. I have page webform1.aspx. I divided the screen into frames. The problem is that, I would like to change the source of the frame dynamically. How can I do this. I am sending querystring to the page webform1.aspx. In that querystring I am sending a page url, that should be added as source to the frame. Could you please help me. Thanks and Regards Gowtham Sen
-
How to give print option to datagrid?Dear Manish, I have one problem that, the datagrid is in the middle of the page. So while I am viewing in the print view, more space is wasted at the header. can we edit the print view page and then print as we want. Is it possible? Another thing is, how to zoom the page. How can we set this option fot it? Could you please give me some idea. Thanks and Regards Gowtham Sen
-
How to give print option to datagrid?Hai Goyal Manish, Thanks a lot. Its working very good. I was surprised very much. If you don't mind can you explain the code line by line briefly. Thanks and Regards Gowtham Sen.
-
How to run sql server jobs with ASP.NET using C#?Hi friends, I have a stored procedure with 4 parameters. I added this to sql server jobs. How can I run this job form asp.net. Is there any way to do this? Could you please give some idea? Thanks and Regards Gowtham sen
-
How to give print option to datagrid?Hi, I have a datagrid in my application. I would like provide an option, whenever that event is fired, the data in datagrid should be printed. How can I do this? could you please give some idea. Thanks and Regards Gowtham Sen
-
About target invocatin exception..!!urgent..plzHi, Thanks a lot. But I have already visited that site. But I didn't find any solution. Could you please give me some other idea. Thanks and Regards Gowtham sen.
-
About target invocatin exception..!!urgent..plzHai friends, I have a requirement that, I need to send mails through .net. But while I am sending I am getting an error message "Exception was thrown by target of invocation exception. How can I resolve this. could you please help me. My code is as follows. msg = new MailMessage(); msg.To = txtMailTo.Text; // to mail address. msg.From="Mail:"; msg.Subject=txtMailSubject.Text ; // mail subject. msg.Body= txtMailBody.Text; // mail body. msg.Priority = MailPriority.Normal; msg.Headers.Add("Mail","Mail"); SmtpMail.SmtpServer=(string)ConfigurationSettings.AppSettings["SmtpServer"]; SmtpMail.Send(msg); ' Thanks and Regards. Gowtham Sen.