Wednesday, June 24, 2009

Dynamic controls in, Adding a dynamic control to a placeholder control and wire up the event in

ASP.NET provides a dedicated control the PlaceHolder control. You can place this control somewhere on your webform and later on use it to hang dynamic controls.

Now i am describing step by step how i generate and use LinkButton Dynamically.
Refer below code to generate Linkbutton at runtime.

Step 1-First take placeholder on your webform

Step 2-write this code on server side in c#

protected override void OnInit(EventArgs e)
for(int i=0;i<5;i++)

LinkButton LinkToEditPage = new LinkButton();

LinkToEditPage.Text = "Name" + i.ToString();
//Add new LinkButton to placeholder
LinkToEditPage.Attributes.Add("IdUser", "LinkButton" + i.ToString());
// Wire up the eventhandler
LinkToEditPage.Click += new EventHandler(LinkToEditPage_Click);

//its Event handler code below

protected void LinkToEditPage_Click(object sender, EventArgs e)
// Get the control and cast it to the
// appropriate type. In our case a LinkButton.

LinkButton LB = (LinkButton)sender;
string IdUser = LB.Attributes["IdUser"];

Response.Write("You Click on " + IdUser);


Step 3-see the output:

when you will run this webform, output will be show like refer below.

when you click on any of one output message will come accordingly.
suppose you have click on secod linkButton output will come as
"You Click on LinkButton2"

I hope this example can give you the idea how to generate dynamic control in and handle their event.

Tuesday, June 23, 2009

ASP.NET MVC for Visual Studio 2010 Available

Microsoft continues to provide solutions orbiting around its next-generation development platform and tools, well after the first public release of Visual Studio 2010 was launched in mid-May, 2009. The latest addition to the list of items designed to expand Visual Studio 2010 is ASP.NET MVC. The web framework tailored specifically for the first beta of Visual Studio 2010 is currently live on Microsoft's open-source project repository
website CodePlex, and is available for download. The company indicated that the bits were in Alpha stage for the time being. View More Information Here

Saturday, June 20, 2009

what is Hibernate Interview Questions

What is Hibernate?

Hibernate is an object-relational mapping (ORM) solution for the language.
it provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database.Hibernate is a powerful, high performance object/relational persistence and query service. This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.

What is NHibernate?
NHibernate is an Object-relational mapping (ORM) solution for the Microsoft .NET platform. to know more about click here to know NHibernate

What is ORM?

ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.

What are the benefits of ORM and Hibernate?

There are many benefits from these. Out of which the following are the most important one.

1. Productivity – Hibernate reduces the burden of developer by providing much of the functionality and let the developer to concentrate on business logic.
2. Maintainability – As hibernate provides most of the functionality, the LOC for the application will be reduced and it is easy to maintain. By automated object/relational persistence it even reduces the LOC.
3. Performance – Hand-coded persistence provided greater performance than automated one. But this is not true all the times. But in hibernate, it provides more optimization that works all the time there by increasing the performance. If it is automated persistence then it still increases the performance.
4. Vendor independence – Irrespective of the different types of databases that are there, hibernate provides a much easier way to develop a cross platform application.

Thursday, June 18, 2009

sql query using substring function in sqlserver

Lets take a example suppose there is table - "tbl_emp"
contain column like tbl_emp(first_name,Last_name,"column3","column4",...)

suppose one row contain data like this:

First_name, last _name , "column3","column4",...
amit , pathak ,'..',''

now in result if you want name will show as Apathak in place of amit pathak
we can use this Query using substring function of sqlserver


Result: Apathak


I more expale of SUBSTRING with CHARINDEX function

I have seen a problem of one person detail below.

i have string like 1017 , 9 , 10-06-2009 , 1|'5001','FORMAN S COMMISSION ','9','2','0','0',10-06-2009,1|'5002','DEFAULT INTEREST (CHITTY)','9','2','0','0',10-06-2009,1

i want to remove first part i.e 1017 , 9 , 10-06-2009 , 1
and i want to use rest part of the string....


use substring function with charindex you will get string what you desire.......
i have seen problem there is "|" char find common in every column so on that behalf i have split the string and provide the need full result.

select substring('1017 , 9 , 10-06-2009 , 1|5001,FORMAN S COMMISSION', charindex( '|','1017 , 9 , 10-06-2009 , 1|5001,FORMAN S COMMISSION')+1, len('1017 , 9 , 10-06-2009 , 1|5001,FORMAN S COMMISSION')) from tbl_emp

SUBSTRING ( Pattern match,STRING)
result will be position of pattern where it matches.
Exp: SUBSTRING ( "M","AMIT Pathak") result will 2 because M is found on 2nd position in string "AMIT Pathak".

Wednesday, June 10, 2009

how to insert data from one table to another table in sql server

Every DBA needs to transfer data between tables.
lets we have create a table that has the following structure,

create table tbl_product_Information(
product_name char(50),
price float,
EntryDate datetime

and now we wish to insert one additional row into the table of the product data.

We will hence use the following SQL script:

INSERT INTO tbl_product_Information(product_name, price,Entry Date)
VALUES ('ABC', 900, 'Jan-10-1999')

Above is the very simple insert command.

The second type of INSERT INTO allows us to insert multiple rows into a table. Unlike the previous example, where we insert a single row by

specifying its values for all columns, we now use a SELECT statement to specify the data that we want to insert into the table. If you are thinking

whether this means that you are using information from another table, you are correct. The syntax is as follows:

INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"

So this is the way you can insert data from one table to another table in sql server.

Tuesday, June 2, 2009

No value given for one or more required parameters - soultion : insert values into database using

How to Insert values into msaccess database using oledb and find the solution of error "No value given for one or more required parameters" :

Dim myOleDbConnection As OleDb.OleDbConnection
Dim insert As String
Dim value1, value2, value3, value4 As String

value1 = "'" & "ContactID" & "'" ' So to avoid the error("No value given for one or more required parameters") use ' single qoutes before and end of coulumn value
value2 = "'" & "FirstName" & "'"
value3 = "'" & "LastName" & "'"
value4 = "'" & "Sent" & "'"


Dim myConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Documents and Settings\Administrator\Desktop\schoolapp\SchoolApp\school.mdb;"
'"Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source = C:\Users\Edward\Desktop\db1.mdb;"

insert = "INSERT INTO Cancelled (ContactID, FirstName, LastName, Sent) VALUES (" & value1 & " ," & value2 & " ," & value3 & " ," & value4 & ")"

myOleDbConnection = New OleDb.OleDbConnection(myConnectionString)
Dim myOleDbCommand As New OleDb.OleDbCommand(insert, myOleDbConnection)

myOleDbCommand = myOleDbConnection.CreateCommand

myOleDbCommand.CommandType = CommandType.Text

myOleDbCommand.CommandText = insert



Catch ex As Exception
End Try

'-------Correct Query--------
' when you trace the value of insert will be : INSERT INTO Cancelled (ContactID, FirstName, LastName, Sent) VALUES ('ContactID' ,'FirstName' ,'LastName' ,'Sent')

'------Wrong Query-------
' basically the problem ("No value given for one or more required parameters") accurs when insert query will be :
' INSERT INTO Cancelled (ContactID, FirstName, LastName, Sent) VALUES (ContactID ,FirstName ,LastName ,Sent)
' because here inserted values doesn't have ' single quotes before and end of coulmn value which is mandatory while inserting data.

End Sub

Free to c sharp and c sharp to code converter free online

You can find Free to c sharp and c sharp to code converter free online
vist this site Free to c# code converter