Saturday, July 28, 2012

Find Particular Column in a Database

Hi guys Now you can find the table name if you know the column name in a Database
Here we go
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 '%Fee%'
ORDER BY schema_name, table_name;

Note:-Fee is my column name


Thursday, May 24, 2012

TOO Many Arguments Specified Resolved

Heloo to all, Now guys i am going to tell you that how you can check your Sql datasource parameters.
when you pass parameters from .aspx page,mostly time you get an error

TOO MANY ARGUMENTS SPECIFIED

To check it you have to call updating method

protected void SqlDataSource2_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
     
        for (int i = 0; i < e.Command.Parameters.Count; i++)
        {
            Trace.Write(e.Command.Parameters[i].ParameterName);
            if (e.Command.Parameters[i].Value != null)
            {
                Trace.Write(e.Command.Parameters[i].Value.ToString());
            }
        }
    }


with this you can check each value by parameter wise

Monday, May 14, 2012

Retrieve only Time in sql

Hello to all Now i will tell you that how to fetch only time from GetDate() function

SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20),  GetDate() , 100), 7))

Make checkbox checked,Unchecked according to status 0&1 at .aspx page

Hello to all Now I am going to tell you that How can You bind checkbox in datalist and make it Checked and unchecked in .aspx page itself. No Need to do code at .cs page


 <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2">
                    <ItemTemplate>
                      
                                <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Eval("status").ToString() == "1" ? true : false %>' />
                           
                    </ItemTemplate>
                </asp:DataList>

Thursday, April 19, 2012

Sql Date ISDATE

ISDATE  function is used to check whether the date is valid or not.

Suppose you have a column nvarchar in which you are storing dates

select ISDATE(yourdate) from  YourTable

If Valid then it return 1  and if not then 0

Thursday, March 15, 2012

Return two parameter from stored procedure

Suppose in stored procedure we have like this

set @lastinserted=(select ident_current('user_referencerecord'))
 set @exist=0
Now to return two variables
select @exist as exist,@lastinserted as lastinserted

To recieve at .cs page

using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                while (rdr.Read())
                {
                    returnval1=rdr.GetInt32(rdr.GetOrdinal("exist"));
                    int returnval2 = rdr.GetInt32(rdr.GetOrdinal("lastinserted"));
                }


            }