private void LinqQuery() {
var query = (from c in fsDs.TypedDataTable
select c.Column1)
.Union(from c in fsDs.TypedDataTable
select c.Column2).Distinct().OrderBy(s => s);
}
private void LinqQuery() {
var query = (from c in fsDs.TypedDataTable
select c.Column1)
.Union(from c in fsDs.TypedDataTable
select c.Column2).Distinct().OrderBy(s => s);
}
This will put a pdf on a web page:
<object data=”test.pdf” type=”application/pdf” width=”300″ height=”200″>
alt : <a href=”test.pdf”>test.pdf</a></object>
I need to look for a stored proc across many databases in the same Sql Server. I was able to get the needed results using the following:
select ‘select ‘ + char(39) + name + char(39) +
‘ as [DBName], [name] from ‘ + name + ‘.dbo.sysobjects where xtype = ‘
+ char(39) + ‘P’ + char(39) + ‘and name = ‘ + char(39) + ‘{Stored Procedure Name}’
+ char(39) + ‘ UNION ALL’ from sysdatabases
After this is run the results will be as follows:
select ‘master’ as [DBName], [name] from master.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘tempdb’ as [DBName], [name] from tempdb.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘model’ as [DBName], [name] from model.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘msdb’ as [DBName], [name] from msdb.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘pubs’ as [DBName], [name] from pubs.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘Northwind’ as [DBName], [name] from Northwind.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
The last UNION ALL must be removed or the follow error will display:
Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near ‘ALL’.
After removing the UNION ALL for the last select is should look as follows:
select ‘master’ as [DBName], [name] from master.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘tempdb’ as [DBName], [name] from tempdb.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘model’ as [DBName], [name] from model.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘msdb’ as [DBName], [name] from msdb.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘pubs’ as [DBName], [name] from pubs.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
UNION ALL
select ‘Northwind’ as [DBName], [name] from Northwind.dbo.sysobjects
where xtype = ‘P’and name = ‘{StoredProcName}’
This will return a select statement that when run will list the name of the server as well as the name of the stored proc that is searched for.
Results will be as follows:
DBName name
——— ———-
master {StoredProcName}
model {StoredProcName}
private void OrderListItems(System.Web.UI.WebControls.ListControl lc, string[] textValues) {
ArrayList al = new ArrayList();
foreach (System.Web.UI.WebControls.ListItem li in lc.Items) {
al.Add(li);
}
lc.Items.Clear();
foreach (string s in textValues) {
foreach (System.Web.UI.WebControls.ListItem li in al) {
if (li.Text == s) {
lc.Items.Add(li);
}
}
}
}
private string FilterValues(DataRow dr, params string[] parm) {
ArrayList al = new ArrayList();
foreach (string s in parm) {
al.Add(dr[s].ToString());
}
string[] sArray = (string[]) al.ToArray(typeof(string));
return string.Join(“,”, sArray);
}
I needed to order records but there was no way to order it based upon setting the sort method to order it. I had to create a method that would sort the records based upon the values that were out of order based upon the sort. This is the method that was used:
private DataSet OrderRecords(DataSet ds, string fieldName, string[] values) {
DataSet retVal = new DataSet();
DataTable dt = ds.Tables[0].Copy();
DataRow[] drArray = new DataRow[values.Length];
dt.Rows.CopyTo(drArray, 0);
ds.Tables[0].Clear();
foreach (string s in values) {
foreach (DataRow dr in drArray) {
if (dr[fieldName].ToString().IndexOf(s) != -1) {
ds.Tables[0].ImportRow(dr);
break;
}
}
}
retVal = ds;
return retVal;
}
To get the item number of the item that was checked in a CheckBoxList for Visual Studio 2003 use the following:
int itemNumber = Convert.ToInt32(Request.Form[“__EVENTTARGET”]
.Substring(Request.Form[“__EVENTTARGET”].LastIndexOf(“:”) + 1));
To create a scrolling grid that will retain position after postback (only for IE)
<div style=”overflow: auto; height: 75px” id=”scrollGrid” runat=”server” onscroll=”updateScroll(this);”>
<asp:datagrid id=”DataGrid1″ runat=”server” useaccessibleheader=”True” />
</div>
<asp:datagrid id=”DataGrid1″ runat=”server” useaccessibleheader=”True” />
<input type=”hidden” id=”scrollTop” runat=”server” />
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Header) {
e.Item.Attributes[“style”] = “position:relative; top:expression
(this.offsetParent.scrollTop);”;
}
else if (e.Item.ItemType == ListItemType.Footer) {
//e.Item.Attributes[“style”] = “position:relative; top:expression(this.offsetParent.clientHeight – this.offsetParent.scrollHeight + this.offsetParent.scrollTop + 40)”;
}
}
private void RegisterScrollScript() {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(“<script type=\”text/javascript\”>”);
sb.Append(” function updateScroll(gridDiv) {“);
sb.Append(” document.getElementById(\”” + scrollTop.ClientID + “\”).value = gridDiv.scrollTop;”);
sb.Append(” }”);
sb.Append(” function setContentScrollPos(gridDiv) {“);
sb.Append(” document.getElementById(gridDiv).scrollTop = document.getElementById(\”” + scrollTop.ClientID + “\”).value;”);
sb.Append(” }”);
sb.Append(“</script>”);
RegisterClientScriptBlock(“MaintainScrollPos”, sb.ToString());
RegisterClientScriptBlock(“SetScrollPos”, “<script type=’text/javascript’>setContentScrollPos(‘” + scrollGrid.ClientID + “‘);</script>”);
}
<script type=”text/javascript”>
function updateScroll(gridDiv) {
document.getElementById(“scrollTop
“).value = gridDiv.scrollTop;
}
function setContentScrollPos(gridDiv) {
document.getElementById(gridDiv).scrollTop = document.getElementById(“scrollTop”).value;
}
</script>
<script type=’text/javascript’>
setContentScrollPos(‘scrollGrid’);
</script>
I needed to create a comma delimited list from xslt. Here is 2 ways to do it:
<!– Add the comma to each item but the last –>
<xsl:for-each select=“TagName“>
<xsl:value-of select=“.“ />
<xsl:if test=“position() != last()“>
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
The following is a class that will format a string as a querystring:
public class QueryStringFormatter { private Dictionary<string, string> _Items = new Dictionary<string, string>(); public Dictionary<string, string> Items { get { return _Items; } set { _Items = value; } } public override string ToString() { string retVal = string.Empty; if (_Items.Count > 0) { List<string> list = new List<string>(); foreach (KeyValuePair<string, string> kvp in _Items) { list.Add(string.Format("{0}={1}", kvp.Key, kvp.Value)); } retVal = "?" + string.Join("&", list.ToArray()); } return retVal; } }