Friday, July 01, 2016

Validate Email Format. Check format of email address



To check if email format is correct
  1. Copy the code below.
  2. Open any workbook.
  3. Press Alt + F11 to open the Visual Basic Editor (VBE).
  4. Press Ctrl + R to show the Project Explorer.
  5. Right-click desired file on left (in bold).
  6. From the Menu, choose Insert-Module.
  7. Paste the code into the right-hand code window.
  8. Close the VBE, save the file  as VBA Enabled WorkBook (xlsm) for Excel 2010 and newer

Friday, June 10, 2016

Search specific Table for a value

When you need to find a value but are not sure in which column it appears. Table is too large to search by each column.
Two separate stored procedures.

Thursday, December 29, 2011

looking for a specific column name in all tables in a database.



SELECT name
FROM sysobjects
WHERE id IN
(
SELECT id
FROM syscolumns
WHERE name like '%thepartofthefieldnameyouarelookingfor%'
)


Sunday, November 27, 2011

c# connect to SQL database through webconfig


1:  protected void Page_Load(object sender, EventArgs e)  
2:    {  
3:      String UserID, UserName, UserEmail, UserFullName;  
4:      //==== Value Assignment ================================================  
5:      //----USER ID  
6:      UserID = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();  
7:      txtUserName_Def.Text = UserID;  
8:      int backslashIndex = UserID.IndexOf("\\") + 1;  
9:      int userCharNum = UserID.Length;  
10:      UserID = UserID.Substring(backslashIndex, userCharNum - backslashIndex);  
11:      //----USER NAME & USER EMAIL  
12:      String strConnectionString = ConfigurationManager.ConnectionStrings["EmpSale2009ConnectionString"].ConnectionString;  
13:      SqlConnection myConnection = new SqlConnection(strConnectionString);  
14:      myConnection.Open();  
15:      SqlCommand command = new SqlCommand("SELECT userName, userEmail, FullName FROM users WHERE userName='" + UserID + "'", myConnection);  
16:      command.ExecuteNonQuery();  
17:      SqlDataReader myreader = command.ExecuteReader();  
18:      while (myreader.Read())  
19:      {  
20:        UserName = (string)myreader["userName"];  
21:        UserEmail = (string)myreader["userEmail"];  
22:        UserFullName = (string)myreader["FullName"];  
23:        txtUserName_Def.Text = UserFullName;  
24:      }  
25:      myreader.Close();  
26:      myConnection.Close();      
27:    }  

Wednesday, June 30, 2010

search database for a value

 
 

CREATE PROC SearchAllTables  
 (  
      @SearchStr nvarchar(100)  
 )  
 AS  
 BEGIN  
      -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.  
      -- Purpose: To search all columns of all tables for a given search string  
      -- Written by: Narayana Vyas Kondreddi  
      -- Site: http://vyaskn.tripod.com  
      -- Tested on: SQL Server 7.0 and SQL Server 2000  
      -- Date modified: 28th July 2002 22:50 GMT  
      CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))  
      SET NOCOUNT ON  
      DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)  
      SET @TableName = ''  
      SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')  
      WHILE @TableName IS NOT NULL  
      BEGIN  
           SET @ColumnName = ''  
           SET @TableName =   
           (  
                SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))  
                FROM      INFORMATION_SCHEMA.TABLES  
                WHERE           TABLE_TYPE = 'BASE TABLE'  
                     AND     QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName  
                     AND     OBJECTPROPERTY(  
                               OBJECT_ID(  
                                    QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)  
                                     ), 'IsMSShipped'  
                                   ) = 0  
           )  
           WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)  
           BEGIN  
                SET @ColumnName =  
                (  
                     SELECT MIN(QUOTENAME(COLUMN_NAME))  
                     FROM      INFORMATION_SCHEMA.COLUMNS  
                     WHERE           TABLE_SCHEMA     = PARSENAME(@TableName, 2)  
                          AND     TABLE_NAME     = PARSENAME(@TableName, 1)  
                          AND     DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')  
                          AND     QUOTENAME(COLUMN_NAME) > @ColumnName  
                )  
                IF @ColumnName IS NOT NULL  
                BEGIN  
                     INSERT INTO #Results  
                     EXEC  
                     (  
                          'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)   
                          FROM ' + @TableName + ' (NOLOCK) ' +  
                          ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2  
                     )  
                END  
           END       
      END  
      SELECT ColumnName, ColumnValue FROM #Results  
 END