Saturday, January 10, 2015

How to find tables in FileGroup in SQL Server?

To find all the objects / tables / Indexes  that exist in a Filegroup, use following query:

SELECT
      f.[name] AS [FileGroupName]
    , OBJECT_SCHEMA_NAME(p.object_id) AS [Schema]
    , OBJECT_NAME(p.object_id) AS [Table]
    , i.name AS [Index]
    , p.rows AS [Row Count]
    , i.type_desc AS [Index Type]
FROM sys.indexes i
INNER JOIN sys.filegroups f
ON i.data_space_id = f.data_space_id
INNER JOIN sys.all_objects o
ON i.object_id = o.object_id
INNER JOIN sys.partitions p
ON i.object_id = p.object_id
AND p.index_id = i.index_id
WHERE o.type = 'U' -- User Created Tables
-- and f.name = '<filter for interested filegroup using name>'
order by p.rows

Monday, December 8, 2014

How to send images in Mail vb.net?

Create Mail message object
Build HTML string for images
Add HTML string in AlternateView
Add images as LinkedResources in AlternateView
Add AlternateView to Mail message.

Below code will demonstrate the steps:

 
 Dim fileNames As String() = System.IO.Directory.GetFiles("C:\imageFolder\", "*.png")  
 Dim mailMsg As MailMessage = New MailMessage()  
 Dim imageHTML as String = String.Empty  
 Dim htmlView As AlternateView
   
 For i As Int16 = 0 To fileNames.Count - 1  
      imageHTML = imageHTML & "<table style=""padding:0px;margin:0px;border:2 solid black;""><tr><td valign=""top"" align=""left""><img width=720 height=930 src=cid:" & System.IO.Path.GetFileName(fileNames(i)) & "></td></tr></table>"  
 Next  

 htmlView = AlternateView.CreateAlternateViewFromString(imageHTML, Nothing, "text/html")
  
 For i As Int16 = 0 To fileNames.Count - 1  
      ' Linked source take physical image path to embed image.  
      Dim imagelink As LinkedResource = New LinkedResource(fileNames(i))  
      imagelink.ContentId = System.IO.Path.GetFileName(fileNames(i)) 'imgFile.Name  
      imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64  
      htmlView.LinkedResources.Add(imagelink)  
 Next  

 mailMsg.AlternateViews.Add(htmlView)  

Happy Coding!

Wednesday, October 22, 2014

Data at the root level is invalid. Line 1, position 1

If you getting error mention in subject, use the following way to load file:

   
   Dim iXmlDocument As XmlDocument  
   iXmlDocument = Getxmldocument(sFilePath)  
   LoadNodes(iXmlDocument)  
        
   Function Getxmldocument(ByVal sFilePAth As String) As XmlDocument  
   
     Dim xmlDOC As New XmlDocument  
   
     Using myXmlTextReader As New XmlTextReader(sFilePAth)  
       myXmlTextReader.XmlResolver = Nothing  
       Dim settings As XmlReaderSettings = New XmlReaderSettings()  
       settings.ValidationFlags = Schema.XmlSchemaValidationFlags.None  
       settings.ProhibitDtd = False  
       settings.ValidationType = ValidationType.None  
   
       Using reader As XmlReader = XmlReader.Create(myXmlTextReader, settings)  
         result.Load(reader)  
         reader.Close()  
       End Using  
   
       myXmlTextReader.Close()  
       settings = Nothing  
     End Using  
   
     Return xmlDOC  
   End Function  
      
   ' load nodes...  
   Public Function LoadNodes(ByRef xmlFileReader As XmlDocument) As Boolean  
   
     Dim xNodeList As XmlNodeList  
     Dim xNode As XmlNode  
     xNodeList = xmlFileReader.SelectNodes("/Tag1/innerTag1")  
     ......  
     .......  
   End Function  

Friday, September 26, 2014

Access RadGrid on Client using Javascript/Jquery

To access RadGrid on client, use following code.
I will also show the code that doesn't work:

 
// didnt work. .Net crash saying The Controls collection cannot be modified because the control contains code blocks (i.e. <%--<% %>--%>)
<%--var grid1 = $find("<%= RadGrid1.ClientID%>");--%>

//didnt work. This just gives Null.   
<%--var grid1 = $find("<%# RadGrid1.ClientID%>"); --%> 

//didnt work. This just gives Null.  
<%--var grid1 = document.getElementById('<%# RadGrid1.ClientID%>') --%> 

//didnt work. It give me ID of RadGrid; not a reference to object.  
var grid1 = document.getElementById('RadGrid1').id;  

//This gives reference as htmldiv control which still cant be used to access functions of radgrid.  
var grid1 = document.getElementById('RadGrid1')

  
// THIS WORKS **********************************************
  
var grid = $find(document.getElementById("RadGrid1").id);

var masterTable = grid.get_masterTableView();
  
//********************************************
  

Thursday, September 25, 2014

Add js reference in aspx page

Hello All,

While working on some js code, I couldn't figure out that why my function declared in js external file not being fired from LinkButton.
I had reference inside head tags which was WRONG.
The reference need to be inside <body> under <form> tag.

<body>
<form id="form1" runat="server">       
<script type="text/javascript" src="scripts/grid.js" ></script>
.
.
.
.

Tuesday, September 23, 2014

Insert Variable along with data in SQL

Create a table with some data in it:
       

create table #data (name varchar(500))
insert into #data (name)
select 'Texas'
union 
select 'LA'
union 
select 'Kansas'
union 
select 'New York'

-- Create Dest Table 
create table #dest (id int, name varchar(500))

-- Select the code below to insert into #dest table 
declare @vid int
set @vid = 1 <-- Any value 

insert into #dest (id, name)
select @vid, s.name from 
(select name from #data) s 
------------------------------------------------------

insert into #dest (id, name)
select @vid , (select top 10 name from #data) <-- This will give subquery return more than 1 row error message 


 

Monday, September 22, 2014

Javascript breakpoint VS 2013

In VS 2013, there is a bug that wont let debugger to stop at the breakpoint.

The workaround is to add "debugger" keyword in js code before the line of breakpoint and then debugger will stop / hit the breakpoint.

Here is the MS connect solution

HTH