Click here to Skip to main content
15,887,585 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Problem Regarding JavaScript Pin
Christian Graus15-Mar-09 22:06
protectorChristian Graus15-Mar-09 22:06 
QuestionConnection string web.config file Pin
Subin Alex15-Mar-09 20:35
Subin Alex15-Mar-09 20:35 
AnswerRe: Connection string web.config file Pin
kumar_k50815-Mar-09 20:44
kumar_k50815-Mar-09 20:44 
GeneralRe: Connection string web.config file Pin
Subin Alex15-Mar-09 20:46
Subin Alex15-Mar-09 20:46 
AnswerRe: Connection string web.config file Pin
Reza Raad15-Mar-09 20:59
Reza Raad15-Mar-09 20:59 
GeneralRe: Connection string web.config file Pin
Subin Alex15-Mar-09 21:19
Subin Alex15-Mar-09 21:19 
AnswerRe: Connection string web.config file Pin
kumar_k50815-Mar-09 21:25
kumar_k50815-Mar-09 21:25 
QuestionProblem in fetching excel sheet Pin
bhii15-Mar-09 20:13
bhii15-Mar-09 20:13 
hi all
im trying to fetch excel sheet and store it in to sql server2000 which contains 20000+ records.
i tried thid code but it wont work


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.OleDb;

public partial class Excel2Sql : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void insertdata_Click(object sender, EventArgs e)
{
OleDbConnection oconn = new OleDbConnection
(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("sun16.xls") + ";Extended Properties=Excel 8.0");//OledbConnection and
// connectionstring to connect to the Excel Sheet
try
{

//After connecting to the Excel sheet here we are selecting the data
//using select statement from the Excel sheet
OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", oconn);
oconn.Open();
//Here [Sheet1$] is the name of the sheet
//in the Excel file where the data is present
OleDbDataReader odr = ocmd.ExecuteReader();
string fname = "";
string lname = "";
string mobnum = "";
string city = "";
string state = "";
string zip = "";
while (odr.Read())
{
fname = valid(odr, 0);//Here we are calling the valid method
lname = valid(odr, 1);
mobnum = valid(odr, 2);
city = valid(odr, 3);
state = valid(odr, 4);
zip = valid(odr, 5);
//Here using this method we are inserting the data into the database
insertdataintosql(fname, lname, mobnum, city, state, zip);
}
oconn.Close();
}
catch (DataException ee)
{
lblmsg.Text = ee.Message;
lblmsg.ForeColor = System.Drawing.Color.Red;
}
finally
{
lblmsg.Text = "Data Inserted Sucessfully";
lblmsg.ForeColor = System.Drawing.Color.Green;
}


}

protected string valid(OleDbDataReader myreader, int stval)//if any columns are
//found null then they are replaced by zero
{
object val = myreader[stval];
if (val != DBNull.Value)
return val.ToString();
else
return Convert.ToString(0);
}

protected void viewdata_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Integrated Security=true;Initial Catalog=FuelDB;Data Source=" + Server.MapPath("example.xls") + "Extended Properties=Excel 8.0");
try
{
SqlDataAdapter sda = new SqlDataAdapter("select * from emp", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (DataException de)
{
lblmsg.Text = de.Message;
lblmsg.ForeColor = System.Drawing.Color.Red;
}
finally
{
lblmsg.Text = "Data Shown Sucessfully";
lblmsg.ForeColor = System.Drawing.Color.Green;
}

}

public void insertdataintosql(string fname, string lname,
string mobnum, string city, string state, string zip)
{//inserting data into the Sql Server
SqlConnection conn = new SqlConnection("Integrated Security=true;Initial Catalog=FuelDB;Data Source=" + Server.MapPath("example.xls") + "Extended Properties=Excel 8.0");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into emp(fname,lname,mobnum,city,state,zip)values(@fname,@lname,@mobnum,@city,@state,@zip)";
cmd.Parameters.Add("@fname", SqlDbType.NVarChar).Value = fname;
cmd.Parameters.Add("@lname", SqlDbType.NVarChar).Value = lname;
cmd.Parameters.Add("@mobnum", SqlDbType.NVarChar).Value = mobnum;
cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = city;
cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = state;
cmd.Parameters.Add("@zip", SqlDbType.Int).Value = Convert.ToInt32(zip);
cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}

protected void deletedata_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Integrated Security=true;Initial Catalog=FuelDB;Data Source=" + Server.MapPath("example.xls") + "Extended Properties=Excel 8.0");
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "delete from emp";
cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteScalar();
conn.Close();
}
catch (DataException de1)
{
lblmsg.Text = de1.Message;
lblmsg.ForeColor = System.Drawing.Color.Red;
}
finally
{
lblmsg.Text = "Data Deleted Sucessfully";
lblmsg.ForeColor = System.Drawing.Color.Red;
}
}
}




above code gives a error sheet$ not found, so
plz help me out in this plz
AnswerRe: Problem in fetching excel sheet Pin
Christian Graus15-Mar-09 20:38
protectorChristian Graus15-Mar-09 20:38 
QuestionHai friends, could you help me please in asp.net Pin
abglorie15-Mar-09 19:30
abglorie15-Mar-09 19:30 
AnswerRe: Hai friends, could you help me please in asp.net Pin
Abhijit Jana15-Mar-09 20:00
professionalAbhijit Jana15-Mar-09 20:00 
AnswerRe: Hai friends, could you help me please in asp.net Pin
kumar_k50815-Mar-09 20:37
kumar_k50815-Mar-09 20:37 
GeneralRe: Hai friends, could you help me please in asp.net Pin
abglorie16-Mar-09 1:07
abglorie16-Mar-09 1:07 
Questionhow to show data in horizontal form ...... Pin
anujbanka178415-Mar-09 19:08
anujbanka178415-Mar-09 19:08 
AnswerRe: how to show data in horizontal form ...... Pin
Alok Sharma ji15-Mar-09 19:11
Alok Sharma ji15-Mar-09 19:11 
GeneralRe: how to show data in horizontal form ...... Pin
anujbanka178415-Mar-09 19:20
anujbanka178415-Mar-09 19:20 
AnswerRe: how to show data in horizontal form ...... Pin
Christian Graus15-Mar-09 19:11
protectorChristian Graus15-Mar-09 19:11 
GeneralRe: how to show data in horizontal form ...... Pin
anujbanka178415-Mar-09 19:27
anujbanka178415-Mar-09 19:27 
GeneralRe: how to show data in horizontal form ...... Pin
Abhijit Jana15-Mar-09 20:02
professionalAbhijit Jana15-Mar-09 20:02 
GeneralRe: how to show data in horizontal form ...... Pin
Christian Graus15-Mar-09 20:39
protectorChristian Graus15-Mar-09 20:39 
AnswerRe: how to show data in horizontal form ...... Pin
Abhijit Jana15-Mar-09 19:13
professionalAbhijit Jana15-Mar-09 19:13 
QuestionRegular Expression Help Pin
Member 345333115-Mar-09 19:02
Member 345333115-Mar-09 19:02 
AnswerRe: Regular Expression Help Pin
Sunil Lanke15-Mar-09 19:39
Sunil Lanke15-Mar-09 19:39 
GeneralRe: Regular Expression Help Pin
Member 345333115-Mar-09 20:19
Member 345333115-Mar-09 20:19 
GeneralRe: Regular Expression Help Pin
Sunil Lanke15-Mar-09 21:27
Sunil Lanke15-Mar-09 21:27 

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.