eg: Label1.ForeColor = System.Drawing.Color.Gray;

Programming is fun and interesting. As you all know, sometime we programmers stucks in the middle way of coding without getting a solution. Blogs like this will help us to find a path to solve our problems. The contents of this blog are the solutions that I found by myself and from other sources. Sharing such solutions is also interesting. Thank you!
Sunday, August 18, 2013
Read and Write data from Excel sheet - Asp.net
Write
OleDbConnection connection = new OleDbConnection();
int i;
string name, email;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/Excel/" + filename);
string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
string connectionString3 = connectionString + connectionString1;
connection.ConnectionString = connectionString3;
string str = "select * from [Sheet1$]";
OleDbDataAdapter adp = new OleDbDataAdapter(str, connection);
DataTable dt = new DataTable();
adp.Fill(dt);
for (i = 0; i < dt.Rows.Count; i++)
{
obj.insert("tb_customer", "cust_name,cust_mailid", "'" + dt.Rows[i]["Customer Name"].ToString() + "','" + dt.Rows[i]["Email"].ToString() + "'");
}
GridView1.DataSource = dt;
GridView1.DataBind();
Read
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("Excel\\"+filename);
string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
string connectionString3 = connectionString + connectionString1;
connection.ConnectionString = connectionString3;
using (DbCommand command = connection.CreateCommand())
{
string sel = "SELECT * FROM [Sheet1$]";
connection.Open();
DataTable dt = new DataTable();
OleDbDataAdapter ada = new OleDbDataAdapter(sel, connectionString3);
ada.Fill(dt);
}
OleDbConnection connection = new OleDbConnection();
int i;
string name, email;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/Excel/" + filename);
string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
string connectionString3 = connectionString + connectionString1;
connection.ConnectionString = connectionString3;
string str = "select * from [Sheet1$]";
OleDbDataAdapter adp = new OleDbDataAdapter(str, connection);
DataTable dt = new DataTable();
adp.Fill(dt);
for (i = 0; i < dt.Rows.Count; i++)
{
obj.insert("tb_customer", "cust_name,cust_mailid", "'" + dt.Rows[i]["Customer Name"].ToString() + "','" + dt.Rows[i]["Email"].ToString() + "'");
}
GridView1.DataSource = dt;
GridView1.DataBind();
Read
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("Excel\\"+filename);
string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
string connectionString3 = connectionString + connectionString1;
connection.ConnectionString = connectionString3;
using (DbCommand command = connection.CreateCommand())
{
string sel = "SELECT * FROM [Sheet1$]";
connection.Open();
DataTable dt = new DataTable();
OleDbDataAdapter ada = new OleDbDataAdapter(sel, connectionString3);
ada.Fill(dt);
}
Audio player (Embed audio) in asp.net
<object id="AudioPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
>
<param name="AutoStart" value="True" />
<param name="URL" value="<%=filePath %>" />
<param name="uiMode" value="full" />
<param name="volume" value="100" />
<!-- Turn off the controls -->
<embed autostart="1" height="100%" name="AudioPlayer" showcontrols="1" src='<%=filePath %>'
type="application/x-mplayer2" volume="10" width="100%"></embed>
</object>
>
<param name="AutoStart" value="True" />
<param name="URL" value="<%=filePath %>" />
<param name="uiMode" value="full" />
<param name="volume" value="100" />
<!-- Turn off the controls -->
<embed autostart="1" height="100%" name="AudioPlayer" showcontrols="1" src='<%=filePath %>'
type="application/x-mplayer2" volume="10" width="100%"></embed>
</object>
Months using dropdown list in asp.net
DateTime month = DateTime.Parse("1/1/1990");
for (i = 0; i < 12; i++)
{
DateTime nmonth = month.AddMonths(i);
string dmonth = nmonth.ToString("MMMM");
DropDownList1.Items.Insert(i, dmonth);
}
OR
string str = DateTime.Now.ToShortDateString();
DateTime cmonth = DateTime.Parse(str);
string mon = cmonth.ToString("MMMM");
if (DropDownList1.SelectedItem.Text != mon)
{
DropDownList1.ClearSelection();
DropDownList1.Items.FindByText(mon).Selected = true;
}
for (i = 0; i < 12; i++)
{
DateTime nmonth = month.AddMonths(i);
string dmonth = nmonth.ToString("MMMM");
DropDownList1.Items.Insert(i, dmonth);
}
OR
string str = DateTime.Now.ToShortDateString();
DateTime cmonth = DateTime.Parse(str);
string mon = cmonth.ToString("MMMM");
if (DropDownList1.SelectedItem.Text != mon)
{
DropDownList1.ClearSelection();
DropDownList1.Items.FindByText(mon).Selected = true;
}
Subscribe to:
Posts (Atom)