Skip to main content

Posts

Showing posts from May, 2013

How to create a csv from a datatable

How to create a csv from a datatable In a project I’ve been working on I came across the need export a DataTable to CSV and this is how I did it.  I have split up the functionality as I also use them to concatenate several DataTables into one CSV. I need to import for following namespaces in this example. using System.Data.SqlClient; using System.Text; The first method gets the DataTable.  It could easily be changed to use stored procedures and add parameters. private DataTable GetDataTable() {     SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);     SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM MyTable", con);     DataTable dt = new DataTable();     using (con)     {         da.Fill(dt);     }     return dt; } The next method creates the CSV using a StringBuilder.  First it create...

SQL SERVER – DBCC RESEED Table Identity Value – Reset Table Identity

DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, YourTable has 25 rows with 25 as last identity. If we want next record to have identity as 35 we need to run following T SQL script in Query Analyzer. DBCC  CHECKIDENT  ( yourtable ,  reseed ,  34 ) If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error. ref:  http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/

how to use render method in asp.net

Replacing the text (sachin) to (S.K.) using Render method and also create link on (S.K.) Default Page ASPX <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>how to use render method in asp.net</title> </head> <body>     <form id="form1" runat="server">     <div>         <div>             <b>Example 1:</b> sachin         </div>         <div>             <b>Example 2:</b> Sachin         </div>         <div>       ...