Friday, June 19, 2009
Thursday, June 18, 2009
sql query using substring function in sqlserver
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
SELECT UPPER(SUBSTRING(FIRST_NAME,1,1)) + '' + LAST_NAME AS NAME FROM TBL_EMP
Result: Apathak
DETAIL OF SUBSTRING FUNCTION BELOW:
SUBSTRING ( STRING,START POSITION,NO OF CHARACTERS REQUIRED POSITION)
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....
Solution:
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
DETAIL OF CHARINDEX FUNCTION BELOW:
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
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 vb.net
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" & "'"
Try
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)
myOleDbConnection.Open()
Dim myOleDbCommand As New OleDb.OleDbCommand(insert, myOleDbConnection)
myOleDbCommand = myOleDbConnection.CreateCommand
myOleDbCommand.CommandType = CommandType.Text
myOleDbCommand.CommandText = insert
myOleDbCommand.ExecuteNonQuery()
myOleDbConnection.Close()
Catch ex As Exception
Trace.WriteLine(ex.ToString)
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 vb.net to c sharp and c sharp to vb.net code converter free online
vist this site Free vb.net to c# code converter
Friday, May 29, 2009
How to read xml file in asp.net
Here is an XML save as name "countries.xml":
-------Create xml file follow image below----------------------------

-------End of xml File-----------------------------------------------------------
---------Code Snap-shot-------------

Out Put: Radiobuttonlist will generate like displayed below :
India | ||
America | ||
Spain |
New Features in ASP.NET 3.5
ASP.NET AJAX
With ASP.NET AJAX, developers can quickly create pages with sophisticated, responsive user interfaces and more efficient client-server communication by simply adding a few server controls to their pages. Previously an extension to the ASP.NET runtime, ASP.NET AJAX is now built into the platform and makes the complicated task of building cross-platform, standards based AJAX applications easy.
New ListView and DataPager Controls
The new ListView control gives you unprecedented flexibility in how you display your data, by allowing you to have complete control over the HTML markup generated. ListView‘s template approach to representing data is designed to easily work with CSS styles, which comes in handy with the new Visual Studio 2008 designer view. In addition, you can use the DataPager control to handle all the work of allowing your users to page through large numbers of records.
LINQ and other .NET Framework 3.5 Improvements
With the addition of Language Integrated Query (LINQ) in .NET Framework 3.5, the process of building SQL queries using error-prone string manipulation is a thing of the past. LINQ makes your relational data queries a first-class language construct in C# and Visual Basic, complete with compiler and Intellisense support. For Web applications, the ASP.NET LinqDataSource control allows you to easily use LINQ to filter, order and group data that can then be bound to any of the data visualization controls like the ListView and GridView controls. In addition, all the other improvements to .NET Framework 3.5, including the new HashSet collection, DateTime offset support, diagnostics, garbage collection, better thread lock support, and more, are all available to you in your ASP.NET applications.
WCF Support for RSS, JSON, POX and Partial Trust
With .NET Framework 3.5, Windows Communication Foundation (WCF) now supports building Web services that can be exposed using any number of the Internet standard protocols, such as SOAP, RSS, JSON, POX and more. Whether you are building an AJAX application that uses JSON, providing syndication of your data via RSS, or building a standard SOAP Web service, WCF makes it easy to create your endpoints, and now, with .NET Framework 3.5, supports building Web services in partial-trust situations like a typical shared-hosting environment.
New Web Features in Visual Studio 2008
New Web Design Interface
Visual Studio 2008 has incorporated a new Web designer that uses the design engine from Expression Web. Moving between design and source view is faster than ever and the new split view capability means you can edit the HTML source and simultaneously see the results on the page. Support for style sheets in separate files has been added as well as a CSS properties pane which clarifies the sometimes-complex hierarchy of cascading styles, so that it is easy to understand why an element looks the way it does. In addition Visual Studio 2008 has full WYSIWYG support for building and using ASP.NET Nested Master Pages which greatly improves the ability to build a Web site with a consistent look and feel.
JavaScript Debugging and Intellisense
In Visual Studio 2008, client-side JavaScript has now become a first-class citizen in regards to its debugging and Intellisense support. Not only does the Intellisense give standard JavaScript keyword support, but it will automatically infer variable types and provide method, property and event support from any number of included script files. Similarly, the JavaScript debugging support now allows for the deep Watch and Locals support in JavaScript that you are accustomed to having in other languages in Visual Studio. And despite the dynamic nature of a lot of JavaScript, you will always be able to visualize and step into the JavaScript code, no matter where it is generated from. This is especially convenient when building ASP.NET AJAX applications.
Multi-targeting Support
In previous versions of Visual Studio, you could only build projects that targeted a single version of the .NET Framework. With Visual Studio 2008, we have introduced the concept of Multi-targeting. Through a simple drop-down, you can decide if you want a project to target .NET Framework 2.0, 3.0 or 3.5. The builds, the Intellisense, the toolbox, etc. will all adjust to the feature set of the specific version of the .NET Framework which you choose. This allows you to take advantage of the new features in Visual Studio 2008, like the Web design interface, and the improved JavaScript support, and still build your projects for their current runtime version.