<connectionStrings>
<!--<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True; User Instance=True" providerName="System.Data.SqlClient"/>
-->
<add name="ConnectionString" connectionString="Data Source=mssql2005.kensoft.net;Database=myDatabase;uid=myUserId;pwd=myPassword" providerName="System.Data.SqlClient" />
</connectionStrings>
Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.
Thursday, September 27, 2007
Connecting to Kensoft.net SQL Server 2005 database
The side note for this is that the database name in Kensoft has an '_' in it, not a '.'.
Copying a MDF SQLExpress Database file to SQL Server 2005 Server
Copying a MDF SQLExpress Database objects to SQL Server 2005:
Next
link to download Microsoft SQL Server Management Studio Express
Note: Be careful with constraint options. I also had to copy and paste the data from the source to target data tables in Microsoft SQL Server Management Studio Express like an Excel copy and paste.
First make sure myDatabase.mdf is on your local machine unless you already
have remote access enabled.
Open Microsoft SQL Server Management Studio Express. Hint: Run as Administrator on Vista.
Make sure myDatabase is listed as a Database in the Object Explorer,
otherwise attach it.
Right click myDatabase -> Tasks -> Generate Scripts -> [select]
myDatabase -> Select All ... ->Script to new Query Window -> Finish
Next
In the Object Explorer open the remote database where you want the copied
tables and views.
Right click myTargetDatabase ->Tasks -> New Query
Paste in copied script from step 4 from above.
Run
link to download Microsoft SQL Server Management Studio Express
Note: Be careful with constraint options. I also had to copy and paste the data from the source to target data tables in Microsoft SQL Server Management Studio Express like an Excel copy and paste.
Tuesday, September 25, 2007
Building an AJAX Slide Show in ASP.net
This was almost simple, but then the image paths made plug and chug necessary until the path problem was resolved. The key is to use image paths in the web service without ~/ and without /. Instead just type the directory name and the file name.
Here is the ASPX code:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
/// <summary>
/// Summary description for WebServiceSlideShow
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class WebServiceSlideShow : System.Web.Services.WebService {
public WebServiceSlideShow () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public AjaxControlToolkit.Slide[] GetSlides() {
AjaxControlToolkit.Slide[] slides;
System.Collections.ArrayList alSlideUrls = new ArrayList();
alSlideUrls.Add("_imgLibrary/photo1.jpg");
alSlideUrls.Add("_imgLibrary/photo2.jpg");
alSlideUrls.Add("_imgLibrary/photo3.jpg");
slides = new AjaxControlToolkit.Slide[alSlideUrls.Count];
int i = 0;
foreach (string str in alSlideUrls)
{
slides[i] = new AjaxControlToolkit.Slide(str, str, str);
i++;
}
return slides;
}
}
Here is the ASPX code:
<div style="text-align: center">
<table style="vertical-align: text-top">
<tr>
<td style="width: 278px" nowrap="noWrap" align="center">
<asp:Image ID="ImagePlayer" runat="server" />
</td>
</tr>
<tr>
<td nowrap="nowrap" style="width: 278px" align="center">
<asp:Button ID="btnBack" runat="server" Text="Back" />
<asp:Button ID="btnPlay" runat="server" Text="Play" />
<asp:Button ID="btnNext" runat="server" Text="Next" />
</td>
</tr>
</table>
</div>
<cc1:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="ImagePlayer" AutoPlay="True" Loop="True" NextButtonID="btnNext" PlayButtonID="btnPlay" PlayButtonText="Play" PreviousButtonID="btnBack" SlideShowServiceMethod="GetSlides" SlideShowServicePath="WebServiceSlideShow.asmx" StopButtonText="Pause">
</cc1:SlideShowExtender>
Saturday, September 22, 2007
Proper ViewState use and the coalescing operator
Here is a quick lesson the ViewState object for viewing an object's state. I found the use of the coalescing operator helpful for future use instead of wordy if then else statments.
the more succinct: if (isX ? doA() : elseDoB).
I would describe coalescing as shorthand for: if (isX!=null) then getX() else getB().
public int CompanyID
{
get { return (int)(ViewState["CompanyID"] ?? 0); }
set { ViewState["CompanyID"] = value; }
}
the more succinct: if (isX ? doA() : elseDoB).
I would describe coalescing as shorthand for: if (isX!=null) then getX() else getB().
Monday, September 17, 2007
GridView table headers and iterating over a GridView cells in the row and columns.
Here is a function to get the GridView's table header columns:
Here is how to iterate over the GridView cells to extract row and column data into a string. The cells can be custom delimited. Notice how this does not include Column.HeaderText :
protected string getTableHeaders()
{
string retVal = "";
int TotalColumns = GridView1.Columns.Count;
int col = 0;
for (col = 0; col < TotalColumns; col++)
{
retVal += GridView1.Columns[col].HeaderText;
if ((col + 1) < TotalColumns) retVal += ", ";
}
return retVal;
}
Here is how to iterate over the GridView cells to extract row and column data into a string. The cells can be custom delimited. Notice how this does not include Column.HeaderText :
protected string getDataCells()
{
string retVal = "";
int TotalColumns = GridView1.Columns.Count;
int TotalRows = GridView1.Rows.Count;
int col = 0;
int row = 0;
if (TotalColumns > 0 && TotalRows > 0)
{
for (row =0; row<TotalRows; row++)
{
for (col = 0; col < TotalColumns; col++)
{ // uses arbitrary ',' between column cells
retVal += GridView1.Rows[row].Cells[col].Text;
if ((col + 1) < TotalColumns) retVal += ", ";
}
// uses arbitrary ';' for end of row
retVal += ";";
}
}
return retVal;
}
Sunday, September 16, 2007
DataGridView cell contents and header contents
// How do I get the contents of a GridView cell?
GridView1.Rows[0].Cells[0].Text;
// Note: This will only get the result data and not the table headers a.k.a. column names.
// How do I get the contents of a GridView table header (<th>) a.k.a. column name?
GridView1.Columns[0].HeaderText;
Friday, September 14, 2007
HTML Table header accessibility standards
This fascinating piece of law regarding federal accessibility standards on HTML table headers requires data tables that contain two more rows or columns to identify row and column headers. The header fields that you create render as , and the columns reference the headers. . The bottom line: Use TH for table headers.
ILLEGAL:
LEGAL
Microsoft Article: from excerpt
ILLEGAL:
<TABLE>
<TR><TD>Stock</TD><TD>Price</TD></TR>
<TR><TD>AAPL</TD><TD>133.33</TD></TR>
</TABLE>
LEGAL
<TABLE>
<TR><TH SCOPE="COL">Stock</TH> <TH SCOPE="COL">Price</TH></TR>
<TR><TD>AAPL</TD> <TD>133.33</TD></TR>
</TABLE>
Microsoft Article: from excerpt
To better understand the DataGrid's rendering machinery, it's useful to review how the DataGrid's implementation has changed after the hotfix discussed in Knowledge Base article 823030 ("FIX: DataGrid Made Compliant with Section 508 of the Rehabilitation Act Amendments of 1998"). In ASP.NET 1.1, the DataGrid's markup is not compliant with Section 508 of the Rehabilitation Act Amendments of 1998, a U.S. law regarding accessibility standards. To resolve this problem, Microsoft made a hotfix rollup package available, as explained in the aforementioned article. In short, the act states that data tables that contain two or more rows or columns must clearly identify row and column headers. This means that, at the very minimum, the header row(s) of an HTML table must define its cells through the TH tag instead of the ordinary TD tag.
Subscribe to:
Posts (Atom)