Question: ```
  if (rbMale.Checked == false && rbFemale.Checked == false)
        {
            flag = true;
            e.Cancel = true;
            groupBox1.Focus();
            errorProvider1.SetError(groupBox1, "Please Select the gender");
        }
        else
        {
            e.Cancel = false;
            errorProvider1.SetError(groupBox1,"");
        }  

```

When I check one of the radio buttons. It still shows that red icon Why is it showing that error icon. Please check the code and help me out. Any help would be great. Thanks

Answer: 
You can execute your second query as the parameter in the system proc, `sp_MSforeachdb`

```
EXECUTE master.sys.sp_MSforeachdb 'select TABLE_CATALOG,TABLE_NAME, COLUMN_NAME, DATA_TYPE from [?].INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ''A_SPECIFIC_TABLE_NAME'' '

```

If you want to filter for only certain databases, you can add an additional filter on the TABLE\_CATALOG column to the second query. The TABLE\_CATALOG is the database name.

If you want to make sure you don't get any empty results from databases that don't have any columns that meet the filter, you can put an IF EXISTS() before your query:

```
    EXECUTE master.sys.sp_MSforeachdb 'IF EXISTS(SELECT * from [?].INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ''A_SPECIFIC_TABLE_NAME'')
      select TABLE_CATALOG,TABLE_NAME, COLUMN_NAME, DATA_TYPE from [?].INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = ''A_SPECIFIC_TABLE_NAME'' '

```
Use a dynamic sql in a loop to fetch DB Names or use dynamic sql with cursor

Method 1: Using Loop

```
Declare @ssql nvarchar(max),@DBName varchar(100),@rowcount int,@datatype varchar(10)

Create table #temp(id int identity(1,1) ,DBName varchar(100))

set @rowcount=0
set @datatype='int'

Insert into #temp(DBName)
SELECT [name]  FROM sys.[sysdatabases] WHERE [name] like 'MyDBName%'

while @rowcount<=1
begin

select @DBName=DBName from #temp where id=@rowcount

set @ssql=N'select TABLE_CATALOG,TABLE_NAME, COLUMN_NAME, DATA_TYPE from '+@DBName+'.INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME in (select TABLE_NAME from '+@DBName+'.INFORMATION_SCHEMA.TABLES where TABLE_TYPE=''BASE TABLE'')
and DATA_TYPE='''+@datatype+''''

--select @ssql
exec sp_executesql @ssql

set @rowcount=@rowcount+1
end

```

Method 2: Cursor

```
    Declare @ssql nvarchar(max),@DBName varchar(100),@rowcount int,@datatype varchar(10)
set @rowcount=0
set @datatype='int'
DECLARE cursorDBName CURSOR -- Declare cursor
FOR

SELECT [name]  FROM sys.[sysdatabases] WHERE [name] like 'MyDBName%'
OPEN cursorDBName -- open the cursor

FETCH NEXT FROM cursorDBName

 INTO @DBName

WHILE @@FETCH_STATUS = 0

BEGIN

 set @ssql=N'select TABLE_CATALOG,TABLE_NAME, COLUMN_NAME, DATA_TYPE from '+@DBName+'.INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME in (select TABLE_NAME from '+@DBName+'.INFORMATION_SCHEMA.TABLES where TABLE_TYPE=''BASE TABLE'')
and DATA_TYPE='''+@datatype+''''

--select @ssql
exec sp_executesql @ssql

 FETCH NEXT FROM cursorDBName

   INTO @DBName
END

CLOSE cursorDBName -- close the cursor

DEALLOCATE cursorDBName 

```