Posts

Showing posts from January, 2011

Donate

Bulk Insert Stored Procedure Not Returning 0 Row(s) Affected (Error)

Lately, A while ago, a friend of mine sent me a CSV file whose fields are separated by comma. I followed a link from http://www.sqlteam.com in creating a stored procedure via BULK INSERT. This complex stored procedure inserts rows from a csv file to a database table with a field defined as primary key (identity seed option set). After changing the script from the website and executed the SP below: use clientdb go EXEC Customer_Import 'D:\Csharp progs\Orders\Client.csv' , 2 The message returned in the result pane was: 0 row(s) affected. Wow, how could this happend where in fact, the csv has 50 rows? I've changed other options to the SP but got no luck. The solution i ran into was to re-open the CSV file and save as another file. Ex. (from Client to Client1). So, when i executed the SP above using the other file, it performed perfectly. use clientdb go EXEC Customer_Import 'D:\Csharp progs\Orders\Client1.csv' , 2 So, I guess there mu...

Printing Checkboxes In Crystal Reports.NET

Image
Source: Crystal Reports To display a checkbox on the report, create a new formula field and insert the following formula. If {Field} = True Then 'Display the checkbox of your choice here Formula = Chr( 254 ) Else 'Display empty checkbox Formula = Chr( 168 ) End If

How To Create A Database Schema In SQL Server

Source: http://msdn.microsoft.com/en-us/library/dd207005.aspx In recent versions of sql server specifically 2005 and 2008, the database called Adventure works seems to be a good example with lots of tables to play with. When I tried to open the database, the tables have prefix or have namespace before it. Example: HumanResources.EmployeeAddress In the previous example called northwind and pubs,table names were just one word. So, to create a schema, here's how to do it: create schema < schema_name > go alter schema < schema_name > transfer <dbo.yourtable> go -- show table select * from schema_name .tablename

Ambigous Column Name In SQL Server TSQL Query

If you encounter this error in your TSQL query embedded in C#, you might want to check the table it is being joined. It might be that some field in the other table has the same fieldname. Example Orders - status varchar(90) OrdersSubForm - status varchar(30) Just make sure, you create a prefix of the table name plus the dot and append it in your field. Just like the example below, for the status field. Select Orders.status, OrderNum from Orders right outer join OrderSubForm on OrderSubForm.ID = Orders.ID where (your condition here)

How To Sort DataTable In C# Or VB.NET

Sorting a data table before binding to a data control like gridview or datalist is provided by microsoft through it's predefined methods which is defaultview.sort. Example: //C# dt1.DefaultView.Sort = "Name Desc" ; //VB.NET dt1.DefaultView.Sort = "Name Desc" Where dt1 is your datatable. Or you could create a dataview object as provided by MSDN. Source: MSDN

Ajax Control PopupControlExtender GetProxyForCurrentPopup Not Showing In Visual Studio Intellisense

I was wondering why when I type PopupControlExtender. nothing happens. Supposedly, GetProxyForCurrentPopup method will show. The solution was so simple, I forgot to include the namespace of AjaxControlsToolkit. //add namespace AjaxToolkit using AjaxControlToolkit; //call commit method PopupControlExtender pce = PopupControlExtender.GetProxyForCurrentPopup( this ); pce.Commit( "hi" );

JavaScript Object Oriented Programming Using Prototype

Hello, In JavaScript, each Object can inherit properties from another object, called it's prototype . When evaluating an expression to retrieve a property, JavaScript first looks to see if the property is defined directly in the object. If it is not, it then looks at the object's prototype to see if the property is defined there. This continues up the prototype chain until reaching the root prototype. Each object is associated with a prototype which comes from the constructor function from which it is created. (Source: http://mckoss.com/jscript/object.htm ) Here's an example i created: <html> <head> <script type= "text/javascript" language= "javascript" > function NumberManip() { var result = 0; } NumberManip.prototype.add = function (num1, num2) { this .result = num1 + num2; } NumberManip.prototype.subtract = function (num1, num2) { this .result = num1 - num2; }...

Inner Joins In SQL Server TSQL

Source: TSQL Programming Reference: An inner join applies two logical query processing phases—it applies a Cartesian product between the two input tables like a cross join, and then it filters rows based on a predicate that you specify. Like cross joins, inner joins have two standard syntaxes: ANSI SQL-92 and ANSI SQL-89. Using the ANSI SQL-92 syntax, you specify the INNER JOIN keywords between the table names. The INNER keyword is optional because an inner join is the default, so you can specify the JOIN keyword alone. You specify the predicate that is used to filter rows in a designated clause called ON. This predicate is also known as the join condition. Here are two basic implementations of inner join scripts i created, one with the inner keyword, and the other w/o the inner keyword. select distinct l.LoanNum, ( c .CusLastName + ', ' + c .CusFirstName + ' ' + c .CusMiddleInit) as Name, Status, DateGranted, AmountGranted from...

ASP.NET Web Forms GridView RowUpdating Event Not Getting New Values From Controls

I have a code in rowupdating event which get's values from textbox controls during edit mode. However, when update command button is clicked, the values from the controls were cleared or null. So, I checked the page load event, and found out that I have a code which rebinds the grid when it is not post back since the update link button will trigger postback. Here is the page load code: if (! string .IsNullOrEmpty(Request.QueryString[ "LoanNum" ])) { ShowToControls(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); BindGridDetails(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); } So, the modified pageload code should add a IsPostback condition so that the binding of gridview will not be executed. Here's the modified script: if (! string .IsNullOrEmpty(Request.QueryString[ "LoanNum" ]) && !Page.IsPostBack) { ShowToControls(Convert.ToInt32(Request.QueryString[ "LoanNum" ])); BindGridDe...

Online Syntax Highlighter For Code Posts

As I reviewed my blog, the code snippets seems to be a mess and unpresentable. So I did some googling earlier and found some online syntax highlighter that may come in handy. https://tohtml.com/jScript/ https://quickhighlighter.com/ https://hilite.me

How To Cast Numeric Numbers To Decimal Value Using Suffix In C#

Usually, i do decimal.parse(numeric value) to parse numbers to decimal. But there's a shortcut way to do this. Just append a suffix m or M to the numeric value. decimal balanceBank = 50000.5m; decimal balanceBank = 50000.5M; Source: MSDN

URL Rewritting Resolve URL In My External CSS And JavaScript Files

I have applied url rewritting from scott: URL Rewriting Tutorial to make my url's SEO friendly. However, my css and javascript files are created internally (w/ in the page itself). When i tried separating my css and .js files, I usually encountered javascript errors such as: 1. GetCustomerDetail is undefined [based from Mozilla Firebug] 2. Microsoft JS runtime error: object required [Internet explorer] I tried googling for hours about object required and have'nt found an answer. As i read again scott's article, the last paragraph was a hint regarding how to resolve CSS and image external links. The solution I came up with was using Control.ResolveUrl() so that my external javascript and css files will work. src= '<%= Page.ResolveUrl("yourjsfile")%>' 2: href= '<%= Page.ResolveUrl("yourcssfile")%>' A good resource, but haven't tested yet. Westwind Tutorial FROM MSDN: MSDN

Set Focus ASP.NET Web Forms Control Using Page Setfocus() Method

Hello, Most of the time, i usually have a JavaScript function to set focus a control during pageload. The control.focus() most of the time does not work in my asp.net page. But in an ASP.NET Page control, there is a handy method to focus. Page.Setfocus(Control.ClientID); where Control could be a textbox or button.

Highlight ASP.NET Web Forms GridView Row Using JavaScript

Here's the code on how to highlight an ASP.NET Web Forms GridView row using JavaScript. if (e.row.rowtype == DataControlRowType.DataRow) { e.Row.Attributes.Add( "onclick" , "document.getElementById('" + e.Row.ClientID + "') .style.backgroundColor = 'green';" ); }

Structures Example In C#.NET

Good evening team, Before migrating to .NET, i used to code a lot in C++/C.. One of the topics in data structures was structures .C# also has struct in its arsenal.A structure is similar to a class, but is a value type, rather than a reference type. Structures are declared using the keyword struct and are syntactically similar to classes. Here is the general form of a struct. struct name : interfaces { // member declarations } The name of the structure is specified by name.Structures cannot inherit other structures or classes, or be used as a base for other structures or classes. (Of course, like all C# types, structures do inherit object.) However, a structure can implement one or more interfaces. These are specified after the structure name using a comma-separated list. Like classes, structure members include methods, fields, indexers, properties, operator methods, and events. Structures can also define constructors, but not destructors. However, you cannot define a defaul...

Donate