Wednesday, December 28, 2005

Inserting Null Values into SQL Server "FINALLY"

After many months of frustration I finally discovered the code to post null values into SQL Server.

cmd.Parameters.Add("@Emp_EID", System.DBNull.Value);

Tuesday, November 01, 2005

Validating Multi-line text boxes in ASP.NET using regular expression validator

Validate Multi-line text box in ASP.NET with Regular Expression

^[\s\S]{0,200}$

200 is the Character count

Thursday, October 20, 2005

Friday, October 07, 2005

Custom Validation

Today I created my first custom validation:

public void TextFilled(object sender, ServerValidateEventArgs e)
{
int counter = 0;
if(DropDownList_Awards.SelectedValue.ToString() == "4" && AwardDesc.Text == "")
{
counter++;
}
e.IsValid = (counter == 0) ? true : false;
}

Hower, I made a bad error: DUH!!!!

on the Button Click event add

if (Page.IsValid)
{

}

Tuesday, September 27, 2005

Thursday, September 15, 2005

spcontnt.aspx

Don't forget spcontnt is your key for 'web part' error resolution

Submitted By: Riwut Libinuko, Plasmedia
Posted On: 1/13/2005

Overall Rating: 3 (1 ratings, 1 comments)


Description:
Eventough webpart is very powerfull, but debuging web part is painfull. For example, you forget to put try-catch block in your code - and one day you get error without any clue to edit. Or imagine, you're creating on-the-fly graph web part, and send wrong HTML header to the page. Causing Sharepoint page shows image only and no interface to access.

What should we do ?

Remember that Sharepoint has spcontnt.aspx - an interface to edit web farm content,

http://[YOURSITES/_layouts/1033/spcontnt.aspx?&url=[FULLYENCODED_WEBFARMPAGE]

Change [YOURSITES] to url of your site, and [FULLYENCODED_WEBFARMPAGE] to url to your web farm.aspx page.

Then, close the offending web part.

Wednesday, September 14, 2005

Compiler Error Message: CS0006: Metadata file

Resolution that is working so far however if this starts happening again I will let everyone know.

I saved my solution. Shut down VS.NET deleted the temp folder: 'c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net\files\wow
Reset IIS.

Seems to have cleared up for now.



"Moojjoo" wrote:

> Has anybody else ever seen this problem and know how to resolve it?
>
> Sometimes my app will load and debug other times I get the following:
>
> Compilation Error
> Description: An error occurred during the compilation of a resource required
> to service this request. Please review the following specific error details
> and modify your source code appropriately.
>
> Compiler Error Message: CS0006: Metadata file
> 'c:\windows\microsoft.net\framework\v1.1.4322\temporary asp.net
> files\wow\7a057e9f\806dc5a7\assembly\dl2\da5089d2\a8835932_a2b8c501\rjrt.wow.rules.dll' could not be found
>
> Source Error:
>
>
>
> [No relevant source lines]
>
>
> Source File: Line: 0
>
>
>

Monday, September 12, 2005

Moving a Solution you are developing from one server to another

When moving your sites from one server to another be sure to update all you references to your server. The best way that I found for doing this was using a find and replace.

Two files that make a big difference are the AppID.csproj.webinfo and AppID.sln files

Friday, August 05, 2005

SharePoint Document Library Icons

SharePoint: Adding icons for other document types (like PDF)
I've seen lots of questions on various SharePoint newsgroups about how to get PDF files to show up with the right icon in document libraries. The process is documented in the WSS admin guide, but it's not that easy to find. I'm working with the folks in PSS/Product Team to try to get a KB article on this topic. In the meantime, though, here it is:

At a high level, all you need to do is get the icon into the \template\images directory, and then map the extension to the icon in \template\xml\docicon.xml. Then you reset IIS, and voilà, you have your mapping.

So, let's say you've already dropped icpdf.gif into the \template\images directory. You would then modify docicon.xml to add the mapping that points to the icon (in bold below):

<DocIcons> <ByProgID> <Mapping Key="Excel.Sheet" Value="ichtmxls.gif"/> <Mapping Key="PowerPoint.Slide" Value="ichtmppt.gif"/> <Mapping Key="Word.Document" Value="ichtmdoc.gif"/> </ByProgID> <ByExtension> <Mapping Key="doc" Value="icdoc.gif"/> <Mapping Key="gif" Value="icgif.gif"/> <Mapping Key="htm" Value="ichtm.gif"/> <Mapping Key="html" Value="ichtm.gif"/> <Mapping Key="ppt" Value="icppt.gif"/> <Mapping Key="pdf" Value="icpdf.gif"/> </ByExtension></DocIcons>
Now, let's say you also want to add a new default icon for unknown file types, called icunk.gif. Again, you'd drop the icon in the \template\images directory, but this time you'd modify docicon.xml to add a default value that is used if a matching can't be made by ProgID or Extension (in bold below):

<DocIcons>
<ByProgID>
<Mapping Key="Excel.Sheet" Value="ichtmxls.gif"/>
<Mapping Key="PowerPoint.Slide" Value="ichtmppt.gif"/>
<Mapping Key="Word.Document" Value="ichtmdoc.gif"/>
</ByProgID>
<ByExtension>
<Mapping Key="doc" Value="icdoc.gif"/>
<Mapping Key="gif" Value="icgif.gif"/>
<Mapping Key="htm" Value="ichtm.gif"/>
<Mapping Key="html" Value="ichtm.gif"/>
<Mapping Key="ppt" Value="icppt.gif"/>
<Mapping Key="pdf" Value="icpdf.gif"/>
</ByExtension>
<Default>
<Mapping Value="icunk.gif"/>
</Default>
</DocIcons>

Happy mapping, and don't forget to restart IIS when you're done!

Resource: http://blogs.msdn.com/lauraj/archive/2004/01/21/61187.aspx

Wednesday, August 03, 2005

Streaming images from memory

Well fellow .NET developers I thought you would find this article very helpful. Thanks Troy Tucker for the code snippet on getting the image to stream from memory:

ASP.NET: Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework -- MSDN Magazine, February 2002: http://msdn.microsoft.com/msdnmag/issues/02/02/ASPDraw/ Article is awesome…
//NEW CODE for displaying IMAGE from MEMORY
MemoryStream myStream;
Byte[] imgByte = (Byte[])myCollection;

myStream = new MemoryStream(imgByte);
System.Drawing.Image _image = System.Drawing.Image.FromStream(myStream);

//System.Drawing.Image _newimage = _image.GetThumbnailImage(,, null, new System.IntPtr());
Response.ContentType = "image/jpeg"; //Make sure this is not jpg instead of jpeg!!!!!!!!!!
_image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Monday, July 25, 2005

DataGrid ItemCommand not firing

# re: DataGrid Paging Events not firing 7/25/2005 3:10 PM Moojjoo
Well everyone... Thank you. I read everybody's response and everyone helped out. My problem was with the ItemCommand Event not firing..

Solutions... Use a link instead of a button worked, but since I am developing for a client I must make everything look the same and use a button. Yes I did copy the code from another Grid that was working and have been scratching my head until I found this site "Thank you GOD".

Solution to fix all...

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack )
{
DataGrid.DataBind();
}
}

What a waste of developer time... ARGH I am dying on my time left on my project...

On to solving streaming an image loaded from Active Directory to a object in memory to presenting it to the end user inside a datalist...

.NET got to love it. 2 more years I should be at the professional level and quote my price for hourly wages... LOL....



Wednesday, July 20, 2005

ADO.NET Accessing Data in a DataSet > DataTable > DataRow

Good Stuff if you return one row from the database.

string strSQL_Table = "Update_Employee";
// Populate Text Boxes with data
txtEmpLanID.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[0].ToString();
txtEmpFirstName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[1].ToString();
txtEmpLastName.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[2].ToString();
txtEmpNumber.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[3].ToString();
txtEmpPhone.Text = ds.Tables[strSQL_Table].Rows[0].ItemArray[4].ToString();
string param = ds.Tables[strSQL_Table].Rows[0].ItemArray[5].ToString();
Department_dropdown1.Set_dept_value(param);
this.DataBind();

Tuesday, July 12, 2005

SQL Server Query for all values within a month

I have been working on a project at work and I discovered the following works for retrieving dates from SQL Server:

SELECT * FROM view_Employees_Awards WHERE stringDate BETWEEN '2005-06-01' AND
'2005-07-01' ORDER BY Awarded_Date DESC

The following brings back every date from the beginning of 2005-06-01 00:00:00

To

2005-06-01 23:59:59


Monday, July 11, 2005

Moojjoo Blog

Moojjoo Blog

Learning more about C# logic everyday. I needed a dropdown that would display dates in a reverse order so how do you do this.

for (int i = DateTime.Now.Year; i >= 2000; i--)

Simple thanks to the MVP at the forums in MSDN

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"Moojjoo" wrote:

I am building a dropdown select box for year and want to render the dropdown
in reverse order. Using VB I could use step, but I am unsure how to do this
in C#

Any help would be great.

if (!this.IsPostBack)
{
for (int i = 2000; i <= DateTime.Now.Year; i++)
{
int intSubtractTerm = 0;
ListItem newListItem = new ListItem();
intYear = DateTime.Now.Year;
intSubtractTerm = intYear - i;
intYear = intYear - intSubtractTerm;
newListItem.Value = intYear.ToString();
newListItem.Text = intYear.ToString();
DropDownListYear.Items.Add(newListItem);
}
}

Friday, July 08, 2005

Moojjoo Blog - Using User Controls in Datagrid

And the anwser is:

In the code behind:


str_emp_dept = Convert.ToString(((Department_dropdown)e.Item.FindControl("Department_dropdown2")).Selected_dept_value());

WHOOOOOOHOOOOOOO!!!!!!!!!!!!!!


THE QUESTION IS BELOW... WHEN I GET THE ANSWER I WILL POST IT.

I created an user control (.ascx file) with a DropDownList (DDL) with the
following code behide:

public string Selected_dept_value()
{
string dept_value = dept_dropdown.SelectedValue;
return dept_value;
}

All the values were added via the visual interface.

I have droped this on my .aspx page and everything works fine. When making
additions to my datagrid.

<uc1:department_dropdown id="Department_dropdown1" runat="server"></uc1:department_dropdown>

The problem is when I am editing my datagrid.

Where I have:

<asp:templatecolumn headertext="Department">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Emp_Department") %>
</itemtemplate>
<edititemtemplate>
<uc1:department_dropdown id="Department_dropdown2" runat="server">
</uc1:department_dropdown>
</edititemtemplate>

The DDL displays fine, but I cannot get the values when clicking update:

Here is the error and code behind that it is failing on:

Error: Object reference not set to an instance of an object <-- However I
have the following:

protected Department_dropdown Department_dropdown2;

Code:
str_emp_dept =
((DropDownList)e.Item.FindControl(Department_dropdown2.Selected_dept_value())).SelectedValue;

Wednesday, April 13, 2005

RECORD COUNT ADO.NET, C#

Moojjoo Blog

THE FOLLOWING CODE IS FOR COUNTING RECORDS IN A DATABASE USING ADO.NET, C#

//string countSQL = "SELECT COUNT(userID) FROM CamelHeadCount WHERE userID =" + GetUserName();
string countSQL = "SELECT COUNT(userID) FROM CamelHeadCount WHERE userID = 'DANNELR'";
SqlConnection Conn = new SqlConnection(strConn);
SqlCommand myCommand = new SqlCommand(countSQL, Conn);

Conn.Open();
Int32 recordCount = (Int32) myCommand.ExecuteScalar();

if (recordCount > 0)
{
Response.Write("Our records indicate that you have already confirmed");
Response.End();
}
Conn.Close();

Saturday, April 02, 2005

ADO.NET Error Occurred: Operation must use an updateable query

Error Occurred: Operation must use an updateable query.I keep receiving the following error: 'sliderbutton.gif' Received...Content-Type: image/gifContent-Length: 138File Name: Y:\documents\Another6\sliderbutton.gifError Occurred: Operation must use an updateable query.Does anyone know what is the problem? Thank you for your time.Victorponce22@yahoo.com
Reply

Posted by Faisal Khan on November-22-2003
Give READ/WRITE permissionsYou'll have to give READ/WRITE permissions for the user IUSR_MACHINENAME to the folder where you are trying to upload (i.e. write) files.------------------Faisal Khan.Stardeveloper.com
In Reply To Reply

Posted by spectreman on January-14-2004
This fix worked for me.I found this on another board. I'm using XP pro, which apparently hides true folder permissions control by default... after you turn of this stupid feature, you can then give 'write' permission to All Users for the .mdb.Here's how:okay Chris_Gilbert and all others who have the same Access DB problem. I provided the solution in pervious post for W2K. I was then having same problem on XP Pro and I have solved the problem after searching a LOT. Okay, here is the solution: - open the Explorer - click on Tools and then Folder Options - goto View tab - scroll down all the way and the last item (i think) will say "Use simple file sharing" - uncheck it if it is checked - now, goto appropriate .mdb file and right click - click on properties - goto Security tab - select Everyone from User - check "Write" checkbox under Everyone as a user VOILA.......You have done it!!!!!! This should work now. It worked for me and now I can run SQL command from frontend to update my Access database.
In Reply To Reply

Posted by jrgonline on November-11-2004
This didn't workthis fix didn't work for me.... i'm still getting the same error. i used the files that were available in the ZIP at the end of this article... do I need to change something within any of those files?------------------"America cannot lead the world's future if our elected officials keep us chained to tradition."
In Reply To Reply

Posted by zedfalco on March-29-2005
thanks a lot spectremanthat`s has worked for me. After I was looking for a solution the all day!Thank

Thursday, March 31, 2005

C# ADO.NET

The first step in any database operation is to create a Connection object and establish the connection by calling its Open() method.

Wednesday, March 30, 2005

C# Clearing dropdownlist.listitems

If you are trying to clear a listitems in asp.net simple type the following:

myList.Items.Clear();

Moojjoo Blog

Saturday, March 05, 2005

C# ASP.net Blog

The following is a library of all the things I have learned since using C# ASP.NET.