i am using window application. actually
i am retriving data from database to datatable.i want to show this record which are present in datatable that record will show in a table format using row and column.
public void databind()
{
DateTime today = DateTime.Today;
string str = "SELECT a.Emp_id,a.Project_id,a.Module_Name,a.Work_Desc,c.Emp_Name FROM DPPR a inner join Emp_Master c on a.Emp_id = c.Emp_id where a.Del_Flag=0 and Rpt_Dt='" + today + "'";
SqlDataAdapter da = new SqlDataAdapter(str, con);
DataTable dt = new DataTable();
da.Fill(dt);
StringBuilder sb = new StringBuilder();
sb.Append("
");
foreach (DataColumn dc in dt.Columns)
{
sb.Append(String.Format("
{0}
", dc.ColumnName));
}
sb.Append("
");
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
sb.Append("
");
foreach (DataColumn dc in dt.Columns)
{
sb.Append(String.Format("
public void databind()
{
DateTime today = DateTime.Today;
string str = "SELECT a.Emp_id,a.Project_id,a.Module_Name,a.Work_Desc,c.Emp_Name FROM DPPR a inner join Emp_Master c on a.Emp_id = c.Emp_id where a.Del_Flag=0 and Rpt_Dt='" + today + "'";
SqlDataAdapter da = new SqlDataAdapter(str, con);
DataTable dt = new DataTable();
da.Fill(dt);
StringBuilder sb = new StringBuilder();
sb.Append("
");
foreach (DataColumn dc in dt.Columns)
{
sb.Append(String.Format("
{0}
", dc.ColumnName));
}
sb.Append("
");
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
sb.Append("
");
foreach (DataColumn dc in dt.Columns)
{
sb.Append(String.Format("
have a look at this code.i m using on asp.net...this is reference only,,i think it may helpful to you.mark as answered if it is heplful...
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;
public partial class Default4 : System.Web.UI.Page { private int numOfRows = 0; private int numOfColumns = 0;
protected void Page_Load(object sender, EventArgs e) { // the two paramters are declared globally GenerateTable(numOfColumns, numOfRows); } protected void Button1_Click(object sender, EventArgs e) { //Check if the inputs are numbers if (int.TryParse(TextBox1.Text.Trim(), out numOfColumns) && int.TryParse(TextBox2.Text.Trim(), out numOfRows)) { //Generate the Table based from the inputs GenerateTable(numOfColumns, numOfRows);
//Store the current Rows and Columns In ViewState as a reference value when it post backs ViewState["cols"] = numOfColumns; ViewState["rows"] = numOfRows; } else { Response.Write("Values are not numeric!"); } } private void GenerateTable(int colsCount, int rowsCount) {
//Creat the Table and Add it to the Page Table table = new Table(); table.ID = "Table1"; Page.Form.Controls.Add(table);
// Now iterate through the table and add your controls for (int i = 0; i < rowsCount; i++) { TableRow row = new TableRow(); for (int j = 0; j < colsCount; j++) { TableCell cell = new TableCell(); TextBox tb = new TextBox();
// Set a unique ID for each TextBox added tb.ID = "TextBoxRow_" + i + "Col_" + j; // Add the control to the TableCell cell.Controls.Add(tb); // Add the TableCell to the TableRow row.Cells.Add(cell); }
// Add the TableRow to the Table table.Rows.Add(row); } } protected void Button2_Click(object sender, EventArgs e) { //Check if ViewState values are null if (ViewState["cols"] != null && ViewState["rows"] != null) { //Find the Table in the page Table table = (Table)Page.FindControl("Table1"); if (table != null) { //Re create the Table with the current rows and columns GenerateTable(int.Parse(ViewState["cols"].ToString()), int.Parse(ViewState["rows"].ToString()));
// Now we can loop through the rows and columns of the Table and get the values from the TextBoxes for (int i = 0; i < int.Parse(ViewState["rows"].ToString()); i++) { for (int j = 0; j < int.Parse(ViewState["cols"].ToString()); j++) { //Print the values entered if (Request.Form["TextBoxRow_" + i + "Col_" + j] != string.Empty) { Response.Write(Request.Form["TextBoxRow_" +i+ "Col_" + j] +" "); } } } } } } }
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:10 PM EDT
Are asking for creating DataTable?
Regards,
Iftikar
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Aug 26, 2013, 10:25 PM EDT
The above link explains the bulk copy to SQL.
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 10:30 PM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Aug 26, 2013, 10:31 PM EDT
you can use datagridview control of windows form to show your data in tabular format.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:32 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 10:34 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:36 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 10:37 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:38 PM EDT
Regards,
Iftikar
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 10:46 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:51 PM EDT
Regards,
Iftikar
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 10:56 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 10:58 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:00 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:02 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:07 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:16 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:22 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:23 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:29 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:33 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:35 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:37 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 26, 2013, 11:40 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 26, 2013, 11:43 PM EDT
ranjan sahooRank #5,709 · 289 reputationPosted Aug 27, 2013, 12:05 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 27, 2013, 12:11 AM EDT
selva kumarRank #2,987 · 483 reputationPosted Sep 11, 2013, 2:54 AM EDT
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;
public partial class Default4 : System.Web.UI.Page
{
private int numOfRows = 0;
private int numOfColumns = 0;
protected void Page_Load(object sender, EventArgs e)
{
// the two paramters are declared globally
GenerateTable(numOfColumns, numOfRows);
}
protected void Button1_Click(object sender, EventArgs e)
{
//Check if the inputs are numbers
if (int.TryParse(TextBox1.Text.Trim(), out numOfColumns) && int.TryParse(TextBox2.Text.Trim(), out numOfRows))
{
//Generate the Table based from the inputs
GenerateTable(numOfColumns, numOfRows);
//Store the current Rows and Columns In ViewState as a reference value when it post backs
ViewState["cols"] = numOfColumns;
ViewState["rows"] = numOfRows;
}
else
{
Response.Write("Values are not numeric!");
}
}
private void GenerateTable(int colsCount, int rowsCount)
{
//Creat the Table and Add it to the Page
Table table = new Table();
table.ID = "Table1";
Page.Form.Controls.Add(table);
// Now iterate through the table and add your controls
for (int i = 0; i < rowsCount; i++)
{
TableRow row = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
// Set a unique ID for each TextBox added
tb.ID = "TextBoxRow_" + i + "Col_" + j;
// Add the control to the TableCell
cell.Controls.Add(tb);
// Add the TableCell to the TableRow
row.Cells.Add(cell);
}
// Add the TableRow to the Table
table.Rows.Add(row);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//Check if ViewState values are null
if (ViewState["cols"] != null && ViewState["rows"] != null)
{
//Find the Table in the page
Table table = (Table)Page.FindControl("Table1");
if (table != null)
{
//Re create the Table with the current rows and columns
GenerateTable(int.Parse(ViewState["cols"].ToString()), int.Parse(ViewState["rows"].ToString()));
// Now we can loop through the rows and columns of the Table and get the values from the TextBoxes
for (int i = 0; i < int.Parse(ViewState["rows"].ToString()); i++)
{
for (int j = 0; j < int.Parse(ViewState["cols"].ToString()); j++)
{
//Print the values entered
if (Request.Form["TextBoxRow_" + i + "Col_" + j] != string.Empty)
{
Response.Write(Request.Form["TextBoxRow_" +i+ "Col_" + j] +"
");
}
}
}
}
}
}
}
Suthish NairRank #92 · 22.8K reputationPosted Sep 11, 2013, 5:28 AM EDT
http://www.codeproject.com/Articles/23640/How-to-send-DataGridView-contents-by-email
http://stackoverflow.com/questions/16547588/sending-datagridview-to-email
Jeetendra GundRank #97 · 22.1K reputationPosted Sep 16, 2013, 3:44 AM EDT
try this code,
Regards,
Jeetendra
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts