protected void Page_Load(object sender, EventArgs e) { DataTable dt= ReadExcelToTable("E:\\31october\\Excel\\Files\\empdata.xlsx"); }private DataTable ReadExcelToTable(string path) { //Connection String string connstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"; //the same name //string connstring = Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + path + //";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"; using(OleDbConnection conn = new OleDbConnection(connstring)) { conn.Open(); //Get All Sheets Name DataTable sheetsName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[]{null,null,null,"Table"}); //Get the First Sheet Name string firstSheetName = sheetsName.Rows[0][2].ToString(); //Query String string sql = string.Format("SELECT * FROM [{0}]",firstSheetName); OleDbDataAdapter ada =new OleDbDataAdapter(sql,connstring); DataSet set = new DataSet(); ada.Fill(set); return set.Tables[0]; } }
Wednesday, August 14, 2013
How to read excel file data into datatable in c# to store in db
Friday, April 5, 2013
toggle anchor tag text on click of anchor
toggle anchor tag text on click of anchor
JS FIDDLE LINK
id="reply" href="#">reply
$("#reply").click(function() { ($(this).text() === "reply") ? $(this).text("close") : $(this).text("reply"); });
JS FIDDLE LINK
Friday, March 15, 2013
SQL SERVER PIVOT TABLE
create table DailyIncome
(
VendorId nvarchar(10),
IncomeDay nvarchar(10),
IncomeAmount int
)
insert into DailyIncome values ('SPIKE', 'FRI', 100)
insert into DailyIncome values ('SPIKE', 'MON', 300)
insert into DailyIncome values ('FREDS', 'SUN', 400)
insert into DailyIncome values ('SPIKE', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'TUE', 200)
insert into DailyIncome values ('JOHNS', 'WED', 900)
insert into DailyIncome values ('SPIKE', 'FRI', 100)
insert into DailyIncome values ('JOHNS', 'MON', 300)
insert into DailyIncome values ('SPIKE', 'SUN', 400)
insert into DailyIncome values ('JOHNS', 'FRI', 300)
insert into DailyIncome values ('FREDS', 'TUE', 500)
insert into DailyIncome values ('FREDS', 'TUE', 200)
insert into DailyIncome values ('SPIKE', 'MON', 900)
insert into DailyIncome values ('FREDS', 'FRI', 900)
insert into DailyIncome values ('FREDS', 'MON', 500)
insert into DailyIncome values ('JOHNS', 'SUN', 600)
insert into DailyIncome values ('SPIKE', 'FRI', 300)
insert into DailyIncome values ('SPIKE', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'FRI', 300)
insert into DailyIncome values ('JOHNS', 'THU', 800)
insert into DailyIncome values ('JOHNS', 'SAT', 800)
insert into DailyIncome values ('SPIKE', 'TUE', 100)
insert into DailyIncome values ('SPIKE', 'THU', 300)
insert into DailyIncome values ('FREDS', 'WED', 500)
insert into DailyIncome values ('SPIKE', 'SAT', 100)
insert into DailyIncome values ('FREDS', 'SAT', 500)
insert into DailyIncome values ('FREDS', 'THU', 800)
insert into DailyIncome values ('JOHNS', 'TUE', 600)
SELECT * FROM DailyIncome
select * from DailyIncome
pivot (avg (IncomeAmount) for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) as AvgIncomePerDay
select * from DailyIncome
pivot (max (IncomeAmount) for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) as MaxIncomePerDay
select * from DailyIncome
pivot (min (IncomeAmount) for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) as MaxIncomePerDay
select * from DailyIncome
pivot (sum (IncomeAmount) for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) as MaxIncomePerDay
drop table DailyIncome
WEB API
http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-entity-framework/using-web-api-with-entity-framework,-part-1
Friday, March 8, 2013
insert multiple rows sql server 2008
For inserting multiple rows using one insert statement you can do as following example :
declare @dept table
(
DeptId int identity(1,1) not null,
DeptName nvarchar(500)
)
insert into @dept values ('sales'),('marketting'),('hr'),('IT')
select * from @dept
SQL fiddle can be check here
Thursday, March 7, 2013
Get random rows from a table in mysql
if you want to get random rows from your table so you can use rand() function of my sql in order by clause.
so for using this you have to use this in order by clause.
but how its works ? how rand() function generates rows randomly .
actually rand() function generates a random floating-point value
so for using this you have to use this in order by clause.
SELECT id,title,publishDate FROM mytable ORDER BY RAND() LIMIT 5
but how its works ? how rand() function generates rows randomly .
actually rand() function generates a random floating-point value
v
in the range 0
<= v
< 1.0
. If a constant integer argument N
is specified, it is used as the seed value, which produces a repeatable sequence of column valuesTuesday, March 5, 2013
SHOW SERIAL NUMBER IN RDLC REPORT
may be you need to show serial number in your rdlc report then you can use following syntax for showing 1,2,3... continuous on in table field
and if you want to re-generate serial number for each group in rdlc then you can use following syntax
Thanks
=RowNumber(Nothing)
and if you want to re-generate serial number for each group in rdlc then you can use following syntax
=RowNumber("table1_Group1")
where table1_Group1 is group name .
Thanks
Subscribe to:
Posts (Atom)
ASP.NET Core
Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...
-
The error message you encountered ("DeleteService FAILED 1072: The specified service has been marked for deletion") indicates tha...
-
replace html of a div using jquery this is simple . just use .html() method of jquery to set new html for a div . $ ( "#divID...
-
declare @ProductIds nvarchar(50)='18,19' SELECT * FROM products Where (',' + @ProductIds +',' LIKE '%,' ...