Click here to Skip to main content
15,914,905 members
Home / Discussions / C#
   

C#

 
Questionfinding dynamic IP of running client Pin
pawanmishraji4-Jul-06 21:48
pawanmishraji4-Jul-06 21:48 
GeneralRe: finding dynamic IP of running client Pin
Guffa5-Jul-06 0:55
Guffa5-Jul-06 0:55 
QuestionGenerating a Typed DataSet from an XSD-file in VS 2005 Pin
anderslundsgard4-Jul-06 21:11
anderslundsgard4-Jul-06 21:11 
AnswerRe: Generating a Typed DataSet from an XSD-file in VS 2005 Pin
DIMPLE_R4-Jul-06 21:44
DIMPLE_R4-Jul-06 21:44 
QuestionOffice 2007 Toolbar Ribbon Pin
cecildt4-Jul-06 20:56
cecildt4-Jul-06 20:56 
QuestionXML Includes in C# code Pin
urbane.tiger4-Jul-06 20:50
urbane.tiger4-Jul-06 20:50 
QuestionDataGrid to Excel in Windows app. Pin
SysJey4-Jul-06 20:33
SysJey4-Jul-06 20:33 
AnswerRe: DataGrid to Excel in Windows app. Pin
Chetan Ranpariya4-Jul-06 21:11
Chetan Ranpariya4-Jul-06 21:11 
You can use the csv concept.

SqlConnection cn ;

SqlCommand cmd ;

string filename ;

SqlDataReader dr ;

System.Text.StringBuilder sb ;



private void Button1_Click(object sender, System.EventArgs e)

{

cn=newSqlConnection("server=localhost;uid=sa;pwd=;database=northwind");

filename = "products.csv";

cmd = new SqlCommand("select * from products ", cn);

cmd.Connection.Open();

dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

sb = new System.Text.StringBuilder();



//For field Names

for(int i = 0 ;i< = dr.FieldCount - 1;i++)

{

if( i < (dr.FieldCount - 1) )

{

sb.Append("\t" + dr.GetName(i) + "\t" + ",");

}

else

{

sb.Append("\t" + dr.GetName(i) + "\t" + "\n");

}

}



//For field Values

while( dr.Read())

{

for(int i = 0 ;i<= dr.FieldCount - 1;i++)

{

if( i < (dr.FieldCount - 1) )

{

sb.Append("\t" + dr.GetValue(i) + "\t" + ",");

}

else

{

sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");

}

}

}

dr.Close();

cn.Close();

Response.ContentType = "Application/x-msexcel";

Response.AddHeader ("content-disposition", "attachment; filename=" + filename ) ;



//Write the file directly to the HTTP output stream.

Response.Write(sb.ToString());

Response.End();

}



/****************************************************************************

private void btExport_Click(object sender, EventArgs e)
{
string strTemp = String.Empty;

dst = new DataSet();
dst.Tables.Add("UserTable");
string strConnection = "Data Source=QUEST03;Initial Catalog=UserDatabase;User ID=hari; Password=shriji;";
SqlConnection conn = new SqlConnection(strConnection);
conn.Open();
SqlCommand cmd = new SqlCommand("Select * From UserTable",conn);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (StreamWriter sw = new StreamWriter("E:/Hari/Problem_Import_Export/Problem1/test.csv"))
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetName(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetName(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetName(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);

//For field Values
strTemp = String.Empty;
while (dr.Read())
{
for (int i = 0; i <= dr.FieldCount - 1; i++)
{
if (i < (dr.FieldCount - 1))
{
sb.Append("\t" + dr.GetValue(i) + "\t" + ",");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + ",";
}
else
{
sb.Append("\t" + dr.GetValue(i) + "\t" + "\n");
strTemp = strTemp + "\t" + dr.GetValue(i) + "\t" + "\n";
}
}
sw.WriteLine(strTemp);
}
}
dr.Close();
conn.Close();


MessageBox.Show("Data Is Imported Successfully...Test.txt File is Created.");
}
AnswerRe: DataGrid to Excel in Windows app. Pin
Azoli5-Jul-06 20:25
Azoli5-Jul-06 20:25 
GeneralRe: DataGrid to Excel in Windows app. Pin
Azoli5-Jul-06 20:48
Azoli5-Jul-06 20:48 
QuestionDisplay UI controls in Datagrid cell (Its urget pls) Pin
Kais4U4-Jul-06 20:11
Kais4U4-Jul-06 20:11 
QuestionSerialization with different Class-Versions Pin
Tomerland4-Jul-06 20:09
Tomerland4-Jul-06 20:09 
QuestionDebug ActiveX control from C# application [modified] Pin
Maddie from Dartford4-Jul-06 19:58
Maddie from Dartford4-Jul-06 19:58 
QuestionHow to apply certain commands during installation [modified] Pin
Kamran Younus4-Jul-06 19:32
Kamran Younus4-Jul-06 19:32 
Question3 Tier Architecture Code Pin
bml36224-Jul-06 19:12
bml36224-Jul-06 19:12 
AnswerRe: 3 Tier Architecture Code Pin
Praveen Nayak4-Jul-06 22:14
Praveen Nayak4-Jul-06 22:14 
GeneralClickety Police Pin
Colin Angus Mackay4-Jul-06 22:20
Colin Angus Mackay4-Jul-06 22:20 
QuestionPurpose of boxing and unboxing? Pin
Anthony Potts4-Jul-06 18:14
Anthony Potts4-Jul-06 18:14 
AnswerRe: Purpose of boxing and unboxing? Pin
Guffa4-Jul-06 19:02
Guffa4-Jul-06 19:02 
QuestionHow to register .NET assembly Pin
Duong Tien Nam4-Jul-06 17:30
Duong Tien Nam4-Jul-06 17:30 
AnswerRe: How to register .NET assembly Pin
S. Senthil Kumar4-Jul-06 19:18
S. Senthil Kumar4-Jul-06 19:18 
Questionmultiselection of month calendar Pin
toink toink4-Jul-06 15:59
toink toink4-Jul-06 15:59 
AnswerRe: multiselection of month calendar Pin
mav.northwind4-Jul-06 19:46
mav.northwind4-Jul-06 19:46 
Questionplease help Pin
omar el halwagy4-Jul-06 14:35
omar el halwagy4-Jul-06 14:35 
AnswerRe: please help Pin
J4amieC4-Jul-06 22:00
J4amieC4-Jul-06 22:00 

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.