VS shortcut keys
http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx#debug
http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx#debug
CREATE FUNCTION CombineValues(
@F_ID INT --The foreign key from TableA which is used to fetch corresponding records
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @SomeColumnList VARCHAR(8000);
SELECT @SomeColumnList = COALESCE(@SomeColumnList + ', ', '') + CAST(SomeColumn AS varchar(20)) FROM TableB CWHERE C.FK_ID = @FK_ID;
RETURN (
SELECT @SomeColumnList)
END
SELECT ID, Name, dbo.CombineValues(FK_ID) FROM TableA
ref :http://stackoverflow.com/questions/111341/combine-multiple-results-in-a-subquery-into-a-single-comma-separated-value
// -------------------------- // Insert Method // -------------------------- protected void Insert() { using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.RequiresNew)) { // Code for inserting records. scope1.Complete(); } } // -------------------------- // Delete Method // -------------------------- protected void Delete() { using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew)) { // Code for deleting records. scope2.Complete(); } } // -------------------------- // Update Method // -------------------------- protected void Update() { using (TransactionScope scope3 = new TransactionScope(TransactionScopeOption.Required)) { Delete(); Insert(); scope3.Complete(); } }ref:http://forums.asp.net/p/1590144/4183122.aspx
html code
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="DlBillingDetails_RowDataBound"
ShowHeaderWhenEmpty="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" OnRowCommand="dlBillingDetails_RowCommand">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Operating Company">
<ItemTemplate>
<asp:UpdatePanel ID="updPnlOpComp" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddOperatingCompany" runat="server" AutoPostBack="true" ToolTip='<%#DataBinder.Eval(Container, "DataItemIndex")%>'
OnSelectedIndexChanged="ddOperatingCompany_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type of Service">
<ItemTemplate>
<asp:UpdatePanel ID="updPnlTOS" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddtypeOfService" runat="server">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<EmptyDataTemplate>
No records found!
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
protected void ddOperatingCompany_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DropDownList ddOperatingCompany = (DropDownList)sender;
int rowid = Convert.ToInt32(ddOperatingCompany.ToolTip);
DropDownList ddtypeOfService = (DropDownList)dlBillingDetails.Rows[rowid].FindControl("ddtypeOfService");
if (ddtypeOfService != null)
{
FillCombo.TypeOfServices(ref ddtypeOfService, Convert.ToInt32(ddOperatingCompany.SelectedValue)); // my method to fill dropdowns
}
UpdatePanel updPnlTOS = (UpdatePanel)dlBillingDetails.Rows[rowid].FindControl("updPnlTOS");
if (updPnlTOS != null)
{
updPnlTOS.Update();
}
}
catch (Exception ex)
{
Constants.log.Exception("UserControls_EmpBillingAssignment", "ddOperatingCompany_SelectedIndexChanged", "", ex);
}
}
----From Table values to string
CREATE
FUNCTION
[dbo].[ConvertCsvToNumbers]
(
@String
AS
VARCHAR
(8000)
)
RETURNS
@Numbers
TABLE
(Number
INT
)
AS
BEGIN
SELECT
@String =
LTRIM(
RTRIM(
REPLACE
(
ISNULL
(@String,
''
),
' '
/* tab */,
' '
)))
IF (LEN(@String) = 0)
RETURN
DECLARE
@StartIdx
INT
DECLARE
@NextIdx
INT
DECLARE
@TokenLength
INT
DECLARE
@Token
VARCHAR
(16)
SELECT
@StartIdx = 0
SELECT
@NextIdx = 1
WHILE @NextIdx > 0
BEGIN
SELECT
@NextIdx = CHARINDEX(
','
, @String, @StartIdx + 1)
SELECT
@TokenLength =
CASE
WHEN
@NextIdx > 0
THEN
@NextIdx
ELSE
LEN(@String) + 1
END
- @StartIdx - 1
SELECT
@Token =
LTRIM(
RTRIM(
SUBSTRING
(@String, @StartIdx + 1, @TokenLength)))
IF LEN(@Token) > 0
INSERT
@Numbers(Number)
VALUES
(
CAST
(@Token
AS
INT
))
SELECT
@StartIdx = @NextIdx
END
RETURN
END
declare @RoleIds varchar(max)
select @RoleIds = coalesce(@RoleIds + ',','') + convert(varchar, nRoleID)
from EmpRole
WHERE sEmployeeID =10
// Retrieve the underlying data item. In this example
// the underlying data item is a DataRowView object.
DataRowView rowView = (DataRowView)e.Row.DataItem;
// Retrieve the state value for the current row.
String state = rowView["state"].ToString();
// Retrieve the DropDownList control from the current row.
DropDownList list = (DropDownList)e.Row.FindControl("StatesList");
'
<%#DataBinder.Eval(Container, "DataItemIndex")%>'
///
/// Get all the values of an enumeration of Type enumType and bind to a listcontrol
///
/// Enumeration type/// List control ///Array of objects
public static void BindEnumToListControl(Type enumType, ListControl lstControl)
{
Dictionaryenumslist = new Dictionary ();
foreach (int enumValue in Enum.GetValues(enumType))
{
enumslist.Add(enumValue,Enum.GetName(enumType, enumValue));
}
lstControl.DataTextField = "Value";
lstControl.DataValueField = "Key";
lstControl.DataSource = enumslist;
lstControl.DataBind();
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Common { public class Logger { private static string _logFileName = string.Empty; /// <summary> /// Create a statis logger instance for your project /// </summary> /// <param name="filename">Log file name</param> public Logger(string filename = "log.txt") { _logFileName = filename; } /// <summary> /// Used to log an exception information /// </summary> /// <param name="ex"></param> /// <param name="classname"></param> /// <param name="methodName"></param> /// <param name="msg"></param> public void WriteEx(Exception ex, string classname = "", string methodName = "", string msg = "") { try { StreamWriter sw = new StreamWriter(_logFileName, true); sw.WriteLine(string.Format("{0} : {1} : {2} : {3} : {4} ", DateTime.UtcNow.ToShortDateString(), classname, methodName, ex.Message, msg)); } catch { //Do nothing } } /// <summary> /// Used to log any information /// </summary> /// <param name="ex"></param> /// <param name="classname"></param> /// <param name="methodName"></param> /// <param name="msg"></param> public void WriteMsg(string msg, string classname = "", string methodName = "") { try { StreamWriter sw = new StreamWriter(_logFileName, true); sw.WriteLine(string.Format("{0} : {1} : {2} : {3} ", DateTime.UtcNow.ToShortDateString(), classname, methodName, msg)); } catch { //Do nothing } } } }
BEGIN TRANSACTION
BEGIN TRY
Try Statement 1
Try Statement 2
...
Try Statement M
END TRY
BEGIN CATCH
ROLLBACK
Catch Statement 1
Catch Statement 2
...
Catch Statement N
END CATCH
COMMIT
SELECT [Datetime] = CONVERT(datetime,'2010-02-28')
SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name like '%your_column_name%' )
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%your_column_name%'
ORDER BY schema_name, table_name;
SELECT t.name TableName, c.name ColumnName
FROM sys.tables t
JOIN sys.columns c ON t.object_id=c.object_id
b)Before SQL SERVER 2005 you can use below
SELECT SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
SysTypes.[Name] As DataType,
SysColumns.[Length] As Length
FROM
SysObjects INNER JOIN SysColumns
ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes
ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE SysObjects.[type] = 'U'
ORDER BY SysObjects.[Name]
Build Versioning in Azure DevOps Pipelines