2014年7月13日 星期日

[RESOLVED] how to save grid data in DB as well as genarate a word document?


I have few textbox which is outside of gridview and a item template grid, on button click which is outside of gridview. I want to generate a word document in that I want textbox as well as gridview data.



































on button click save data will save in database as well as one word document will genarate which will save in HDD drive.



Someone please  tell me how to do that?



I think you can Use  Batch-Insert with the help of SqlBulkCopy,but first you should create a table in SQL whose scaffoldings are the same as what it is of DataTable


refer more about SqlBulkCopy


http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx


converting grid to doc format


http://www.aspsnippets.com/Articles/Export-Multiple-GridViews-to-Word-Document-in-ASP.Net.aspx


http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel-or.html





Hi,


If I do not misunderstand you, please first save the data in the textbox to the database as following:


string Item = txtPONumber.Text.ToString();

string Quantity = txtCompanyName.Text.ToString();

string ProductDescription= txtOrderNo.Text.ToString();

string strConnString= ConfigurationManager.ConnectionStrings["conString"].ConnectionString;

using (SqlConnection con = new SqlConnection(strConnString))

{

using (SqlCommand cmd = new SqlCommand())

{

cmd.Connection = con;

cmd.CommandType = CommandType.Text;

cmd.CommandText = "INSERT INTO [Customers] VALUES(@Item, @Quantity, @ProductDescription)";

cmd.Parameters.AddWithValue("@Item", Item);

cmd.Parameters.AddWithValue("@Quantity", Quantity);

cmd.Parameters.AddWithValue("@ProductDescription", ProductDescription);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

}

}

Then please export the gridview data to a word document, please try to refer to the following article:



#Export Gridview Data to Word Document in ASP.NET:

http://surajdeshpande.wordpress.com/2013/09/02/export-gridview-data-to-word-document-in-asp-net/ .


Best Regards.


沒有留言:

張貼留言