drpList.Items.Insert(0, new ListItem(String.Empty, String.Empty)); drpList.SelectedIndex = 0;
Author: ErcanOPAK
Capitalize words in SQL (Display data first letter uppercase rest lowercase)
SELECT UPPER(LEFT(colname,1)) + LOWER(RIGHT(colname, LEN(colname) – 1)) FROM tablename
How to solve “TableAdapter can’t see stored procedure returned fields when using temp table” problem
Add these lines to the beginning of your stored procedure. The statement is never executed, but for some reason it gets the job done. I really don’t know how and why 🙂 IF 1=0 BEGIN SET FMTONLY OFF END
Get and Use TextBox Values with Javascript
Here is the example code to get and use TextBox Values with Javascript:
Get the row number “x” from SQL
WITH Records AS (SELECT ROW_NUMBER() OVER(ORDER BY ID_of_your_SQLTable) AS ‘ROW’, * FROM yourSQLTable) SELECT * FROM Records WHERE ROW = X –You can change X with the number you wanna get (For Example ROW = 5 will bring the 5th record)
Add RowNumber to Gridview
<Columns> <asp:TemplateField HeaderText=”RowNumber”> <ItemTemplate> <%# Container.DataItemIndex + 1 %> </ItemTemplate> </asp:TemplateField> … </Columns>
Add Default Value in SQL Server
If there is no default value for the column then you can use this query: ALTER TABLE MyTable ADD CONSTRAINT df_MyTable_MyColumn DEFAULT 0 FOR MyColumn
Search text in all stored procedures in SQL Server
SELECT name FROM sys.procedures WHERE Object_definition(object_id) LIKE ‘%search_parameter%’
Hide GridView Column on server-side
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { e.Row.Cells[index].Visible = false; }
Find numbers with more than two decimal places in SQL
The Problem: In financial databases, you often expect values to have exactly two decimal places (e.g., $10.50). However, due to bulk imports or rounding errors, “hidden” decimals like 10.50001 can creep into your tables. These tiny fractions can cause massive discrepancies in your total sums and reports. The Smart Solution: Instead of slow string parsing, […]
How to change ReportViewer Date Format
=Format(Fields!Date,Value,”dd.MM.yyyy”)
How to return only the Date from a SQL Server DateTime datatype
–You can change GETDATE() with the date you want to use SELECT CONVERT(date, GETDATE())
What does COALESCE do in SQL?
In SQL Server (Transact-SQL), the COALESCE function returns the first non-null expression in the list. If all expressions evaluate to null, then the COALESCE function will return null. SELECT COALESCE(NULL, NULL, ‘ErcanOPAK.com’, NULL, ‘blog.ErcanOPAK.com’); Result: ‘ErcanOPAK.com’ SELECT COALESCE(NULL, ‘ErcanOPAK.com’, ‘blog.ErcanOPAK.com’); Result: ‘ErcanOPAK.com’ SELECT COALESCE(NULL, NULL, 1, 2, 3, NULL, 4); Result: 1
How to find records based on CAPITAL and small letters in SQL Query?
SELECT * FROM SQLTABLE WHERE SUBSTRING(TableColumn, 1, 1) = ‘x’ COLLATE SQL_Latin1_General_CP1_CS_AS
Fire Combobox SelectedIndexChanged with button code-behind
myComboBox_SelectedIndexChanged(myComboBox, new EventArgs()); // or (null, null)
Get a Tree view with SQL Query
First of all, I must thank to Maulik Dhorajia for his great post. That post saved me a lot. That’s the @Company table we will use: And here is the SQL Query we need to use: — Working Example ;WITH CTECompany AS ( SELECT EmpID, ParentID, PersonName , 0 AS HLevel, CAST(RIGHT(REPLICATE(‘_’,5) + CONVERT(VARCHAR(20),EmpID),20) AS […]
Database stuck in “Restoring” state
You can use this command: RESTORE DATABASE <database name> WITH RECOVERY








