Posts

Donate

How To Get ASP.NET Web Forms GridviewRow Selected Index In Row Command Event

In your row command event, add a code like this: int selected_index = Convert.ToInt32(e.CommandArgument);

How To Cast SQL Money Field Type To C# Data Type

Given you have a field called customer_salary which is of type money in sql server, to cast and use it in your c# programs, you cast it to decimal. decimal Price = Convert.ToDecimal(reader.GetValue(1));

Choosing Between ASP.NET MVC And ASP. NET WebForms

I've been playing around asp.net mvc just recently, i was really shocked and somewhat struggling with this new framework since i was used to the traditional N-Tier development with asp.net. As I developed simple examples, asp.net mvc is somewhat similar to n-tier development. As such, each layers have been separated to enable designers and coders to work independently with each layer. I have some books in my arsenal but i haven't read them yet.LOL Basically, I'm still a newbie with this stuff. One tip that i read was choosing between asp.net webforms and asp.net mvc. This will provide insights on other developers as well. Choosing between ASP.NET MVC and ASP.NET Webforms Source: ASP.NET MVC 1.0 Quickly In general, choosing between ASP.NET MVC and ASP.NET can be based on the following five criteria: 1. Are you considering test-driven development (TDD)? TDD enables you to write tests for an application first, after which the application logic is developed. An ASP.NET Webfor

How To Calculate Age In SQL Server T-SQL Using DATEDIFF()

Here is a script to calculate an age of a person using TSQL using Convert(). SELECT FirstName, LastName , CONVERT (Int, DATEDIFF( day , BirthDate, GETDATE())/365.25) As Age FROM EmployeesDTR Source: TSQL Reference

Login Control Never Redirects To Index Or Default Page In ASP.NET Web Forms

Working with login control in asp.net provides convenient way to apply secured user API with less programming. Since login control is part of .net framework,such classes are provided such as membership, forms authentication and etc.. One weird error i encountered is that, it does not redirect to my index page once login has been successful. I implemented my own validation function to check if a user exists in the database. If the method returns true, redirect to index page. See code below. But the fact is, it does not redirect. if (CheckUserInMyDB(Login1.UserName, Login1.Password)) { e.Authenticated = true ; Login1.Visible = false ; Response.Redirect( "Index.aspx" ); } else { e.Authenticated = false ; } So the solution i found in forums.asp.net was to transfer the Response.Redirect to Logged in method of the login control.

Insert Parameter Array In VB.NET

Here's a snippet to insert a parameter array in .NET: ' add a class ex. Patient Public Class Patient Public name As String Public code As Integer End Class ' create a delegate Delegate Function myConn() As String 'function to return connstring Private Function connectionstring() As String Dim conn As String = "your_connection_string here" Return conn End Function '--Main Sub ' execute insert array Dim objCon As myConn objCon = New myConn( AddressOf connectionstring) Dim str As String = objCon.Invoke() Dim connection As New SqlConnection(str) Try Dim patients As New List( Of Patient) For i As Integer = 0 To max_count_variable Dim patient As New Patient()

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)

Donate