Click here to Skip to main content
14,336,087 members
Rate this:
Please Sign up or sign in to vote.
See more:
drop down list concatenation three data text field using sql server 2005 stored procedure.how to solve it.
Posted
Comments
ZurdoDev 13-Mar-13 11:43am
   
Concatenate them together. Where's the issue?
Ashvinrajkot 13-Mar-13 11:56am
   
in drop down list i can display like this BranchName-Vehicletype-Date.e.g. Eagle-Truck-1/1/2013
ZurdoDev 13-Mar-13 11:57am
   
See solution 2.
Ashvinrajkot 13-Mar-13 12:01pm
   
public static void FillDropDownListParcelLoadingID(DropDownList ddl)
{
//Step 1:Create Connection Object

SqlConnection objConn = new SqlConnection();
objConn.ConnectionString = ConfigurationManager.ConnectionStrings["Eagle TradelinkConnectionString"].ToString();
objConn.Open();
//step 2:Create Command Object

SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objConn;

objCmd.CommandType = CommandType.StoredProcedure;
objCmd.CommandText = "PR_ParcelLoading&Unloading_SelectDropDownList";

SqlDataReader objSdr = objCmd.ExecuteReader();
ddl.DataSource = objSdr;
ddl.DataTextField =
ddl.DataValueField = "ParcelLoadingID";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("Select one", "-99"));

//step 3:Close Connection

objConn.Close();
}

in data text field what is given?????
ZurdoDev 13-Mar-13 12:03pm
   
No, in your SQL, concatenate them together.
Ashvinrajkot 13-Mar-13 12:05pm
   
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PR_ParcelLoading&Unloading_SelectDropDownList]

AS

SELECT
[dbo].[ParcelLoading&Unloading].[ParcelLoadingID],
[dbo].[ParcelLoading&Unloading].[BranchID]+'-'
[dbo].[ParcelLoading&Unloading].[VehicleType]+'-'+
[dbo].[ParcelLoading&Unloading].[LoadingDate]

FROM [ParcelLoading&UnLoading]

LEFT OUTER JOIN [dbo].[Branch]
ON [dbo].[Branch].[BranchID] = [dbo].[ParcelLoading&UnLoading].[BranchID]



stored procedure
ZurdoDev 13-Mar-13 12:12pm
   
So, in SQL alias the column. BranchID + ... AS LoadingText. Then LoadText will be a named column and you can set ddl.DataTextField = "LoadingText"
Ashvinrajkot 13-Mar-13 12:19pm
   
explain detail please
ZurdoDev 13-Mar-13 12:27pm
   
[dbo].[ParcelLoading&Unloading].[BranchID]+'-'
[dbo].[ParcelLoading&Unloading].[VehicleType]+'-'+
[dbo].[ParcelLoading&Unloading].[LoadingDate]
AS LoadingText
Ashvinrajkot 13-Mar-13 12:39pm
   
above stored procedure only date can display like as 2012-02-05 00:00:00.000
ZurdoDev 13-Mar-13 14:41pm
   
You can convert it. See link below.
Ashvinrajkot 13-Mar-13 12:56pm
   
solution?????????
CHill60 13-Mar-13 13:10pm
   
See this link for how to format dates in SQL http://www.sql-server-helper.com/tips/date-formats.aspx
Ashvinrajkot 13-Mar-13 12:08pm
   
give solution??

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

SELECT FirstColumn + ISNULL(' ' + SecondColumn , '') + ISNULL(' ' + ThirdColumn , '') from YourTable
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100