Thursday, 31 May 2012

What is difference between Primary Key and Unique key?

Q: What is difference between Primary Key and Unique key, What are the different types of key used in sql server and what is its use what is rollup and cude functions?

Ans : A UNIQUE constraint is similar to PRIMARY key, but you can have more than one UNIQUE constraint per table.
When you declare a UNIQUE constraint, SQL Server creates a UNIQUE index to speed up the process of searching for duplicates. In this case the index defaults to NONCLUSTERED index, because you can have only one CLUSTERED index per table.
* The number of UNIQUE constraints per table is limited by the number of indexes on the table.

* Contrary to PRIMARY key UNIQUE constraints can accept NULL but just once. If the constraint is defined in a combination of fields, then every field can accept NULL and can have some values on them, as long as the combination values is unique.

Wednesday, 30 May 2012

How to insert system date in SQL Server 2008

First create table :

1) create table Test(id int identity(1,1),name varchar(20),V_DATE datetime)
use getDate()  function : 

insert into  Test(name,vDate)  values('Sw',getDate())

select * from Test

Output :
1    Nihar     NULL
2    Rohan    NULL
3    Rohan    NULL
4    Sw         2012-05-30 15:57:35.230

Different Date & time Fornat read this :

select id,name,CONVERT(varchar,vDate,104) from Test   --Date : 30.05.2012

select id,name,CONVERT(varchar,vDate,1) from Test       --Date : 05/30/12

select id,name,CONVERT(varchar,vDate,2) from Test       --Date : 12.05.30

select id,name,CONVERT(varchar,vDate,3) from Test        --Date : 30/05/12

select id,name,CONVERT(varchar,vDate,4) from Test        --Date : 30.05.12

select id,name,CONVERT(varchar,vDate,0) from Test        --Date : May 30 2012  3:57PM

select id,name,CONVERT(varchar,vDate,5) from Test        --Date : 30-05-12

select id,name,CONVERT(varchar,vDate,6) from Test          --Date : 30 May 12

select id,name,CONVERT(varchar,vDate,7) from Test            --Date : May 30, 12

select id,name,CONVERT(varchar,vDate) from Test            --Date : May 30 2012  3:57PM

select id,name,CONVERT(varchar,vDate,8) from Test            -- Time : 15:57:35

select id,name,CONVERT(varchar,vDate,9) from Test          --Date : May 30 2012  3:57:35:230PM

Try it :


For More info. Click on label

SQL Server 2008 Data types

Today I'll will mention the Microsoft SQL Server 2008 Fileds data types, you need to choose the right data type for the database fileds for more speed efficency, and i think the most important thing the fundamental of the database itself.
Let's begin:
  1. char: the char datatype is ifxed in length, if you enter fewer that than the number of character defined the remaining length will be space filled to the right; use this data type when the column dat is to be of fixed length, which tends to be the case foe customer IDs and bank account IDs.
  2. nchar: the nchar type is exactly like char, but will hold characters in unicode formate rather than ANSI; infact SQL Server allocates double the space internally, so unless there is a need in your database to hold this type of character, it's easier to stick with ANSI.
    • Note:
      • ANSI character sets only hold up to 256 char.
      • Unicode character sets only hold up to 65,536 chr.
  3. varchar: the varchar data type holds alphanumeric data; just like char but with flexible size, you just set the maximum number of characters, maximum size is 8,000 character.
  4. nvachar: it's defined in samilier way to varcar but it uses unicode.
  5. text: the text data type holds data is longer than 8,000.
  6. ntext: sae as text type, but holde unicode.
  7. image: is very much like text data tybe, expect it's for any type of binary data, like images, movies, or music.
  8. int: the integer data type is used for holding a anumeric values that don't have any deciaml point, it's rang is between -2,147,483,648 adn 2,147,483,674.
  9. bigint: the bidint or big integer data type same as int but with larger rang, it's rang is between -9,223,372,036,854,77,808 and 9,223,372,036,854,77,807.
  10. smallint: the smallint data type is samilar to int but with smaller rang, it's rang is between -32,768 to 32,767.
  11. tinyint: it's  samller  than smallint data type.
  12. decimal/numeric: both the decimal and numeric data types hold the same rang of data from -10 to the power 38+1 to 10 to he power 38-1.
  13. float: it's used for numbers where the decimal point isn't fixed, it's rang is between -1.79e+308 to 1.79e+308
    • Warning:
      • The values can't always be seen as 100% accurate, as they can be approximate "Rounded".
  14. real: it's like float data type but with wider rand, it's rang between -3.40e+38 to 3.40e+38, and still hold approximate value also.

Tuesday, 29 May 2012



Add a column in a table, use the following syntax:

        ALTER TABLE table_name
        ADD column_name datatype
Delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):

        ALTER TABLE table_name
        DROP COLUMN column_name
Change the data type of a column in a table, use the following syntax:

1) My SQL / SQL Server / MS Access:

ALTER TABLE table_name
ALTER COLUMN column_name datatype
2) Oracle:

ALTER TABLE table_name
MODIFY column_name datatype
You can try it... 
Hopes it will helps you

Monday, 28 May 2012

Allow Only Numbers in a Textbox

It can be possible using .net and javascript

.Net :
        You have asp control to validate you web part.

JavaScript :
           In this , you need to write code in <Script> Tag like

<script language="JavaScript">
function onlyNumbers(evt)
var e = event || evt;  var charCode = e.which || e.keyCode;

 if (charCode > 31 && (charCode < 48 || charCode > 57))
  return false;

 return true;

} </script>

Debugging tricks with Visual Studio


Debugging is important of solving,correcting methods in VS.
Some trick anf facts about debugging .MY friend send me this link ,you have refer  following link. It will help you .
 Debugging is a major part of the development lifecycle. Sometimes challenging, sometimes puzzling, sometimes annoying, one for sure - it is unavoidable for any not-so-trivial program. The progress of debugging tools over the last years has made many debugging tasks much easier and less time-consuming.
This article summarizes ten debugging tricks and techniques that can save you a lot of time when using Visual Studio.

Friday, 25 May 2012

Database session using V$SESSION in Oracle


This view lists session information for each current session.
Column Datatype Description
SADDR RAW(4 | 8) Session address
SID NUMBER Session identifier
SERIAL# NUMBER Session serial number. Used to uniquely identify a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID.
AUDSID NUMBER Auditing session ID
PADDR RAW(4 | 8) Address of the process that owns the session
USER# NUMBER Oracle user identifier
USERNAME VARCHAR2(30) Oracle username
COMMAND NUMBER Command in progress (last statement parsed); for a list of values, see Table 7-5. These values also appear in the AUDIT_ACTIONS table.
OWNERID NUMBER The column contents are invalid if the value is 2147483644. Otherwise, this column contains the identifier of the user who owns the migratable session. For operations using Parallel Slaves, interpret this value as a 4-byte value. The low-order 2 bytes of which represent the session number, and the high-order bytes the instance ID of the query coordinator.
TADDR VARCHAR2(8) Address of transaction state object
LOCKWAIT VARCHAR2(8) Address of lock waiting for; null if none
STATUS VARCHAR2(8) Status of the session:
  • ACTIVE - Session currently executing SQL
  • KILLED - Session marked to be killed
  • CACHED - Session temporarily cached for use by Oracle*XA
  • SNIPED - Session inactive, waiting on the client
SCHEMA# NUMBER Schema user identifier
SCHEMANAME VARCHAR2(30) Schema user name
OSUSER VARCHAR2(30) Operating system client user name
PROCESS VARCHAR2(12) Operating system client process ID
MACHINE VARCHAR2(64) Operating system machine name
TERMINAL VARCHAR2(30) Operating system terminal name
PROGRAM VARCHAR2(48) Operating system program name
TYPE VARCHAR2(10) Session type
SQL_ADDRESS RAW(4 | 8) Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed
SQL_HASH_VALUE NUMBER Used with SQL_ADDRESS to identify the SQL statement that is currently being executed
SQL_ID VARCHAR2(13) SQL identifier of the SQL statement that is currently being executed
SQL_CHILD_NUMBER NUMBER Child number of the SQL statement that is currently being executed
PREV_SQL_ADDR RAW(4 | 8) Used with PREV_HASH_VALUE to identify the last SQL statement executed
PREV_HASH_VALUE NUMBER Used with SQL_HASH_VALUE to identify the last SQL statement executed
PREV_SQL_ID VARCHAR2(13) SQL identifier of the last SQL statement executed
PREV_CHILD_NUMBER NUMBER Child number of the last SQL statement executed
MODULE VARCHAR2(48) Name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure
MODULE_HASH NUMBER Hash value of the above MODULE
ACTION VARCHAR2(32) Name of the currently executing action as set by calling the DBMS_APPLICATION_INFO.SET_ACTION procedure
ACTION_HASH NUMBER Hash value of the above action name
FIXED_TABLE_SEQUENCE NUMBER This contains a number that increases every time the session completes a call to the database and there has been an intervening select from a dynamic performance table. This column can be used by performance monitors to monitor statistics in the database. Each time the performance monitor looks at the database, it only needs to look at sessions that are currently active or have a higher value in this column than the highest value that the performance monitor saw the last time. All the other sessions have been idle since the last time the performance monitor looked at the database.
ROW_WAIT_OBJ# NUMBER Object ID for the table containing the row specified in ROW_WAIT_ROW#
ROW_WAIT_FILE# NUMBER Identifier for the datafile containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.
ROW_WAIT_BLOCK# NUMBER Identifier for the block containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.
ROW_WAIT_ROW# NUMBER Current row being locked. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.
LOGON_TIME DATE Time of logon
LAST_CALL_ET NUMBER If the session STATUS is currently ACTIVE, then the value represents the elapsed time in seconds since the session has become active. If the session STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.
PDML_ENABLED VARCHAR2(3) This column has been replaced by column PDML_STATUS
FAILOVER_TYPE VARCHAR2(13) Indicates whether and to what extent transparent application failover (TAF) is enabled for the session:
  • NONE - Failover is disabled for this session
  • SESSION - Client is able to fail over its session following a disconnect
  • SELECT - Client is able to fail over queries in progress as well
See Also:
FAILOVER_METHOD VARCHAR2(10) Indicates the transparent application failover method for the session:
  • NONE - Failover is disabled for this session
  • BASIC - Client itself reconnects following a disconnect
  • PRECONNECT - Backup instance can support all connections from every instance for which it is backed up
FAILED_OVER VARCHAR2(3) Indicates whether the session is running in failover mode and failover has occurred (YES) or not (NO)
RESOURCE_CONSUMER_GROUP VARCHAR2(32) Name of the session's current resource consumer group
PDML_STATUS VARCHAR2(8) If ENABLED, the session is in a PARALLEL DML enabled mode. If DISABLED, PARALLEL DML enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DML.
PDDL_STATUS VARCHAR2(8) If ENABLED, the session is in a PARALLEL DDL enabled mode. If DISABLED, PARALLEL DDL enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DDL.
PQ_STATUS VARCHAR2(8) If ENABLED, the session is in a PARALLEL QUERY enabled mode. If DISABLED, PARALLEL QUERY enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL QUERY.
CURRENT_QUEUE_DURATION NUMBER If queued (1), the current amount of time the session has been queued. If not currently queued, the value is 0.
CLIENT_IDENTIFIER VARCHAR2(64) Client identifier of the session
BLOCKING_SESSION_STATUS VARCHAR2(11) Blocking session status:
BLOCKING_INSTANCE NUMBER Instance identifier of blocking session
BLOCKING_SESSION NUMBER Session identifier of blocking session
SEQ# NUMBER Sequence number that uniquely identifies the wait. Incremented for each wait.
EVENT# NUMBER Event number
EVENT VARCHAR2(64) Resource or event for which the session is waiting See Also: Appendix C, "Oracle Wait Events"
P1TEXT VARCHAR2(64) Description of the first additional parameter
P1 NUMBER First additional parameter
P1RAW RAW(4) First additional parameter
P2TEXT VARCHAR2(64) Description of the second additional parameter
P2 NUMBER Second additional parameter
P2RAW RAW(4) Second additional parameter
P3TEXT VARCHAR2(64) Description of the third additional parameter
P3 NUMBER Third additional parameter
P3RAW RAW(4) Third additional parameter
WAIT_CLASS_ID NUMBER Identifier of the wait class
WAIT_CLASS# NUMBER Number of the wait class
WAIT_CLASS VARCHAR2(64) Name of the wait class
WAIT_TIME NUMBER A nonzero value is the session's last wait time. A zero value means the session is currently waiting.
SECONDS_IN_WAIT NUMBER If WAIT_TIME = 0, then SECONDS_IN_WAIT is the seconds spent in the current wait condition. If WAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, and SECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) Wait state:
  • 0 - WAITING (the session is currently waiting)
  • -2 - WAITED UNKNOWN TIME (duration of last wait is unknown)
  • -1 - WAITED SHORT TIME (last wait <1/100th of a second)
  • >0 - WAITED KNOWN TIME (WAIT_TIME = duration of last wait)
SERVICE_NAME VARCHAR2(64) Service name of the session
SQL_TRACE VARCHAR2(8) Indicates whether SQL tracing is enabled (ENABLED) or disabled (DISABLED)
SQL_TRACE_WAITS VARCHAR2(5) Indicates whether wait tracing is enabled (TRUE) or not (FALSE)
SQL_TRACE_BINDS VARCHAR2(5) Indicates whether bind tracing is enabled (TRUE) or not (FALSE)

Thursday, 24 May 2012

@@transcount in sql server

Returns the number of BEGIN TRANSACTION statements that have occurred on the current connection .
For ex :
--  The BEGIN TRAN statement will increment the
--  transaction count by 1.
--  The COMMIT statement will decrement the transaction count by 1.

Ex2 :- >
  Step 1:

create table a(m varchar(max), i int)
Step2 : 

declare @cnt int
--Explicit transaction
begin tran
set @cnt=@@trancount
insert into a select 'inside', @@trancount
insert into a select 'inside cnt', @cnt
commit tran

set @cnt=@@trancount

--Implicit transcation
insert into a select 'outside', @@trancount
insert into a select 'outside cnt', @cnt
Step 3 : 

select * from a
Output :
inside    2
inside cnt             1

outside 2
outside cnt         0

References :

Rowcount (@@rowcount) in Sqlserver

@@rowcount  returns number of rows were after affteced after executing sql query/statement.
If the number of rows is more than 2 billion, use ROWCOUNT_BIG

Syntax :: @@rowcount

Example : 1)  Here it will shows you warning like (Here i  have only)

update [TestApp].[dbo].[UpdatedProducts]
set [ProductID]=4
where [ProductID] =6
if @@rowcount=0
PRINT 'Warning: No rows were updated';

Output :

(0 row(s) affected)
Warning: No rows were updated

here my productId=5 exist in table , so it shows

update [TestApp].[dbo].[UpdatedProducts]
set [ProductID]=4
where [ProductID] =6
if @@rowcount=0
PRINT 'Warning: No rows were updated';

Output :

(1 row(s) affected)

Tuesday, 22 May 2012


Query :


FROM [TestApp].[dbo].[MovieDT1]
where boxOfficeTotal > 3000
SELECT ,[Title],[Director],[boxOfficeTotal]

FROM [TestApp].[dbo].[MovieDT1]
where boxOfficeTotal > 4000

Here Output of ths query like

Value between More than 3000 but less than 4000

1)  Except or Not Exist  replaces  use of NOT IN(...)
Instead of using NOT IN in statment query , you can use EXCEPT or NOT EXIST

 2) For better performance ,it works more better than left join or NOT IN

Monday, 21 May 2012

How to Import Excel sheet data to Oracle

Without Toad or an tool :
  1. Save the file as .csv file, then load the file into oracle using sqlLoader.Multiple sheets does not matter how the records are listed matters and how that should go into the db matters.

Now from TOAD go to:

1. Database-->Import-->Table Data
2. Select the proper schema and Table name where data should be inserted
3. Click "Execute Wizard" and specify the type of file to be imported
4. Select "Excel File (.xls)" and click next
5. Give the path of the file, and again click next


nOTE : [ reference :] 

ROWNUM is an Oracle pseudo column which numbers the rows in a result set.
SELECT rownum, table_name
FROM user_tables;
ROWNUM        TABLE_NAME                     
------------- -----------------
1             EMP
2             DEPT
3             BONUS
4             SALGRADE
5             DUMMY
5 rows selected
Here is a summary of how ROWNUM can be used.

Limiting Rows

ROWNUM can be used to limit the number of rows returned by a query in a similar way to LIMIT in Postgres and MySql, TOP in SQL Server and FETCH FIRST in DB2.
SELECT rownum, table_name
FROM user_tables
WHERE rownum <=3;
ROWNUM        TABLE_NAME                     
------------- -----------------
1             EMP                            
2             DEPT                           
3             BONUS
3 rows selected


The use of ROWNUM is not restricted to select statements. It can be used with DML statements that update the database too.
FROM all_objects
WHERE rownum <= 1000;
Table created

SET object_id = rownum,
created = created + INTERVAL '1' MINUTE * rownum 
WHERE rownum <= 100;
100 rows updated

AND rownum = 1;
1 rows deleted
ROWNUM is particularly useful, when used in conjunction with the CONNECT BY LEVEL clause, for creating arbitrary rows in the database. See the article on generating rows in Oracle for more details.

Offsetting Rows

Rows can also be skipped at the beginning of a result set using ROWNUM.
SELECT rnum, table_name
  (SELECT rownum rnum, table_name
   FROM user_tables)
WHERE rnum > 2;
RNUM     TABLE_NAME                     
-------- ---------------- 
3        SALGRADE                       
4        DUMMY                          
5        DEPT
3 rows selected
You will notice that an inline view has been introduced to transform the ROWNUM pseudo column into a 'real' column before we do the comparison.

It is tempting to write the above SQL as follows.
SELECT table_name
FROM user_tables
WHERE rownum > 2;
0 rows selected
However, this query will always return zero rows, regardless of the number of rows in the table.

To explain this behaviour, we need to understand how Oracle processes ROWNUM. When assigning ROWNUM to a row, Oracle starts at 1 and only only increments the value when a row is selected; that is, when all conditions in the WHERE clause are met. Since our condition requires that ROWNUM is greater than 2, no rows are selected and ROWNUM is never incremented beyond 1.

The bottom line is that conditions such as the following will work as expected.

.. WHERE rownum = 1;

.. WHERE rownum <= 10;

While queries with these conditions will always return zero rows.

.. WHERE rownum = 2;

.. WHERE rownum > 10;

Top-n Query

Typically, a top-n query sorts data into the required sequence and then limits the output to a subset of rows.

For example, suppose we wish to retrieve the top three earners from our employee table.
SELECT ename, sal
  SELECT ename, sal
  FROM emp
WHERE rownum <=3;
ENAME      SAL                    
---------- ---------
KING       5000                   
SCOTT      3000                   
FORD       3000
3 rows selected
The inline view (the inner select) sorts the rows and passes the result up to the outer select. The outer select then limits the output to three rows.

It may seem more natural to use the following SQL.
SELECT ename, sal
FROM emp
WHERE rownum <=3
ENAME      SAL                    
---------- ---------------------- 
ALLEN      1600                   
WARD       1250                   
SMITH      800
3 rows selected
However, this does not give us the result we want because Oracle assigns the ROWNUM values to the rows before it does the sort.

In this example, Oracle will retrieve three rows from the table, any three rows, and sort only these three rows. We really need Oracle to sort all the rows and then return the first three. The inline view will ensure that this will happen.

Sort Performance

Limiting rows on a sorted result set using ROWNUM can also provide an added performance benefit. Rather than physically sorting all the rows to retrieve just the top few, Oracle maintains an array which contains just the highest or the lowest values (depending on whether we specified ASC or DESC in the ORDER BY clause). The size of the array will be the number of rows we wish to return. As rows are processed, only the highest (or lowest) values are retained in the array. All other rows are discarded.


Next, we will see how ROWNUM is used to select a range of rows from within a result set. This is useful if we are to provide pagination on a web screen, for example.

Suppose we are paging through the employee table in name order and we wish to display rows six to ten inclusive.
SELECT rnum, ename, job
  (SELECT /*+ FIRST_ROWS(10) */ rownum rnum, ename, job
    (SELECT ename, job
     FROM emp
     ORDER BY ename)
  WHERE rownum <= 10
WHERE rnum > 5;
RNUM     ENAME      JOB       
-------- ---------- --------- 
6        JAMES      CLERK     
7        JONES      MANAGER   
8        KING       PRESIDENT 
9        MARTIN     SALESMAN  
10       MILLER     CLERK
5 rows selected
We use nested inline views to retrieve and sort the data and then apply the range check using ROWNUM. We have split the upper and lower bound check, which allows Oracle to use COUNT(STOPKEY) in the execution plan when checking for ROWNUM <= 10. This is a performance optimization which, along with the sorting optimization described earlier, will ensure that our query runs efficiently as the table grows.

The FIRST_ROWS(n) hint also tells Oracle to optimize the query so that the first n rows are returned as quickly as possible.


ROWNUM provides a mechanism for returning a subset or range of rows from a query. It can be misleading at first if not properly understood but, once mastered, is invaluable for limiting result set output for pagination and top-n style queries.

Friday, 18 May 2012

How to set equal width of columns in Gridview

Suppose you are binding data field with some templates like checkbox,radiobutton,textbox etc...
Then it will works using

< Headerstyle width="6%">

E'g :
...// Some your grridview code

....// Some data fields ..

 <asp:TemplateField Visible="true" HeaderText="Disagree">
                        <HeaderStyle Width="2%"/>
                                <asp:RadioButton ID="rdbtn3" runat="server" GroupName="rdGroup" OnLoad="RadioButtonGroup_load" />


If stll have problem, then post your code in comment...
But it will helps you

Happy Coding  :) :)

Tuesday, 15 May 2012

How to use @@Identity or IDENTITY ?

IDENTITY [ ( seed , increment ) ]


 seed :-  this is for you starting point of number.Means from which number you want to start table data increment (e'g  1,2, -1 ,0 ,100,1001  etc)

increment :-   You can set increment value as per you want (1,2,3...) how much difference you want between two numbers

Note : Identity column 'i' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.

step 1 :   Create table in database

create table #CheckIdentity(i Int Identity,j Int)

step 2 : Insert Values in that database

insert #CheckIdentity select 1

step 3:  Display Values from table

select * from #CheckIdentity

Output :

I        J
1       1
2       1
3       1

Reference :

Link help you lot

How to enable script on browsers

Enable you Javascript of Browsers !! IF you don't have idea , follow the steps
On browser :
  1. Tools -> Internet Options
  2. Security -> Click on " Custom level " tab
  3. Scroll down , thr you will get the Scripting tabs Enable that
  4. close browser , then again check it

Multiple radiobutton without radiobuttonlist in gridview

storing Multiple selected radiobutton's of gridview?


<asp:GridView ID="gvSurvey" runat="server" CellPadding = "4"  OnRowDataBound ="gvSurvey_RowDataBound" BorderWidth ="2"
AutoGenerateColumns="False" EmptyDataText="No data Available" GridLines="None"
HorizontalAlign="Center" ForeColor="#333333" Font-Names="Verdana" ShowFooter="True">
<RowStyle BackColor="White" />
<asp:BoundField DataField="HEADER" HeaderText="Description" ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" />

<asp:TemplateField Visible="true" HeaderText ="Strongly Disagree">
<asp:RadioButton ID="rdbtn1" runat ="server" GroupName ="MyRadioGroup"/>

<asp:TemplateField Visible="true" HeaderText ="Agree">
  <asp:RadioButton ID="rdbtn2" runat ="server"  GroupName ="MyRadioGroup"/>
<asp:TemplateField Visible="true" HeaderText ="Disagree">
  <asp:RadioButton ID="rdbtn3" runat ="server" GroupName ="MyRadioGroup"/>

<asp:TemplateField Visible="true" HeaderText ="Strongly Agree">
  <asp:RadioButton ID="rdbtn4" runat ="server"  GroupName ="MyRadioGroup"/>
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />

 C# :

 for (i = 0; i < gvSurvey.Rows.Count; i++)
                RadioButton rdbtn1 = (RadioButton)gvSurvey.Rows[i].Cells[3].FindControl("rdbtn1");
                RadioButton rdbtn2 = (RadioButton)gvSurvey.Rows[i].Cells[4].FindControl("rdbtn2");
                RadioButton rdbtn3 = (RadioButton)gvSurvey.Rows[i].Cells[5].FindControl("rdbtn3");
                RadioButton rdbtn4 = (RadioButton)gvSurvey.Rows[i].Cells[6].FindControl("rdbtn4");

          //      RadioButton rdbtn1=(RadioButton) gvSurvey.Rows[i].ClientID  

                qtn_no = dtSurvey.Rows[i]["QTN_NO"].ToString();

                if (rdbtn1.Checked)
                    rdbtn1.Text = "1";
                    lblMsg.Text =  "You Procedure/insert query with parameters" .....
                .... (Same for next 3 radiobuttons)


The result of selection formula must be a boolean in Crystal Report

You're attempting to return a date in a selection formula (Whether it is a Record, Group, or Saved Data selection formula) and CR doesn't know how to handle that situation. It must be a boolean because selection formulas essentially tell the report to only include data where the formula evaluates to TRUE.
Instead of  that ,you can directly click "Use Editor" ..  Without selection or group formula you will get all type operators.

Hope this will help you !!

Wednesday, 9 May 2012

Multiple Radiobuttons in gridview


 <asp:TemplateField Visible="true" HeaderText ="Strongly Disagree">
                                                           <%-- <asp:RadioButton ID="rdbtn1" runat ="server" />--%>
                                                           <input name="MyRadioButton1" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />
                                                <asp:TemplateField Visible="true" HeaderText ="Agree">
                                                             <%-- <asp:RadioButton ID="rdbtn2" runat ="server" />--%>
                                                             <input name="MyRadioButton2" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />
                                                <asp:TemplateField Visible="true" HeaderText ="Disagree">
                                                               <%--<asp:RadioButton ID="rdbtn3" runat ="server" />--%>
                                                               <input name="MyRadioButton3" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />
                                                 <asp:TemplateField Visible="true" HeaderText ="Strongly Agree">
                                                          <%-- <asp:RadioButton ID="rdbtn4" runat ="server" />--%>
                                                          <input name="MyRadioButton4" type ="radio" value = "'<%# Eval("SQTN_NO") %>'" />

C# :

protected void btnSubmit_Click(object sender, EventArgs e)
        string selectedValue = Request.Form["MyRadioButton1"];
        lblMsg.Text = selectedValue;
//same for next RadioButton also ....

The debugger cannot continue running the process.Process was terminated

While debugging your code step by step , you will find the line , from where error redirecting.
If you are using  " ToString() " anywhere in that file ,please remove that .
Instead of the ,you can use Value / Text . It works fine.

If you were not used ToString() any where in program , then reload project copy by removing completely.

Test you ODP.NET connection with following program

using System;
using Oracle.DataAccess.Client;

namespace NoOraClient
    class Program
        static void Main(string[] args)
            //You need to enter a valid Oracle connection string, below is the format
            string connectionString = "user id=USERID;password=PASSWORD;" +
                "data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=IPorSERVERNAME)" +

            using (OracleConnection connection = new OracleConnection())
                connection.ConnectionString = connectionString;

                    Console.WriteLine("Connection Successful!");
                    Console.ReadLine();  // stops the console from closing until you hit the ENTER key
                catch (OracleException ex)
                    Console.ReadLine();  // stops the console from closing until you hit the ENTER key

Method Hiding

Method Hiding:
In some situation we may want to have a method in the base class which can be implemented in the derived class independent of the method in the base class i.e we may want to have its new version altogether
In the following code i add a method Hello() in the base class and in the derived class give a completely new definition to the same method by preceding it with 'new' keyword

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
           public class VirtualDemo
                  public virtual double Area(double r)
                        return r * r;
                  public void Hello()
                        Console.WriteLine("Hello in Base Class");
         public class A : VirtualDemo
               public override double Area(double r)
                  double p = 3.142;
                  return base.Area(r) * p;
               public new void Hello()
                  Console.WriteLine("Hello in Derived Class");
         public class Test
            public static void Main(string[] args)
                  A obj1 = new A();
Hello in Derived Class 

~if any class method doesnot have 'virtual','abstract' or 'override' keyword and we attempt to have its new implementation in any derived class a warning is generated to supply 'new' keyword to the method in the derived class.We can also not override that class method unless that method has 'virtual' keyword
That was in brief about Method Overriding. In case of any query ask me on the same blog. In my next article i will explain Abstract Classes and Interfaces with examples and how these all concepts relate to each other and differ from each other with similar and even better approach.

Ask me if you have any query so far after reading the article.