HOME

Monday, January 30, 2012

Export text file from SQL SERVER 2005

----First Enable xp_cmdshell byusing below command


EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE

----now write export query

EXEC xp_cmdshell 'bcp "select * from erp.dbo.tbl_Empleave" queryout "C:\bcptest2.txt" -T -c -t  '


The parameters that were used are:
  • The queryout option allows you to specify a query to export. This could be as simple as the query we have are as complicated as you want.  You can also create a view and select the data from a view.
  • The file name where the results will be stored is placed after the queryout option.
  • The -T parameter specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security. You could use -P (password) and -U (user) if you want to use a SQL Server login.
  • The -c specifies the character dataype will be used for each field.
  • The -t parameter allows you to specify a field delimiter. The character after -t will be used to separate the data fields. If -t is removed, tab will be used as the default delimiter.

Set Primary Key in Excel


press alt+f11

Private Sub worksheet_change(ByVal target As Range)
Dim targ As Range, cel As Range, rg As Range
Set targ = [c1:c15]
'change to the cell range being watched for duplicates
Set targ = Intersect(targ, target)
If targ Is Nothing Then Exit Sub
For Each cel In targ.Cells
If cel <> "" Then Set rg = Columns(cel.Column).Find(cel, LookIn:=xlValues, after:=cel)
If rg.Address <> cel.Address Then
Application.EnableEvents = False
cel = ""
cel.Select
Application.EnableEvents = True
MsgBox "duplicate entry! " & cel.Value
End If
Next
End Sub

and den save as Macro enabled work sheet
and den enable developer tab
and den in developer tab enable the macro security

Tuesday, January 3, 2012

Display word document in text box C#

_Application WordApp = new Microsoft.Office.Interop.Word.Application();

object WordFile = Server.MapPath("~/jobportal/resumescemt/MCA/" + txtEmailID.Text + ".doc");
object RdOnly = false;
object Visible = true;
object Missing = System.Reflection.Missing.Value;
Document Doc = WordApp.Documents.Open(ref WordFile, ref Missing, ref RdOnly, ref Missing, ref Missing,
ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
ref Missing, ref Visible, ref Missing, ref Missing, ref Missing,
ref Missing);
txtResume.Text = Doc.Content.Text;