TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
narasiman rao
NA
519
767.2k
Passing the Cityid using for each loop but only last city id
Aug 26 2016 7:08 AM
public void Getfunction(int j)
{
string connectionString = ConfigurationManager.ConnectionStrings["OneTransportConnectionString"].ConnectionString;
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "select DISTINCT date_TripDate AS TripDate,traveltype.varchar_TravelTypeCode AS TripType,contactss.Value as Mobilenumber,time_TripTime AS ShiftTime,trip.int_VehicleTripID as RequestID,varchar_TravelerID AS AssociateID,(Associate_FirstName + Associate_LastName) AS AssociateName,Gender AS Gender,varchar_ProjectId AS ProjectID,varchar_ProjectName AS ProjectName,city.varchar_CityName AS City,placeee.varchar_PlaceName AS SourceArea,place.varchar_PlaceName AS DestinationArea,varchar_StatusDescription As Status,reason.varchar_ReasonDescription AS AppType"
cmd.CommandText += " from [OneC_988].[dbo].[988_Details_VehicleRequest] request";
cmd.CommandText += " join [OneC_988].[dbo].[988_Details_VehicleTrip] trip on request.int_VehicleRequestID=trip.int_VehicleRequestID";
cmd.CommandText += "and int_CityID = @par ";
cmd.Parameters.Add("@par", SqlDbType.Int).Value = j;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
sqlConnection.Close();
}
static void Main(string[] args)
{
Program ps = new Program();
int[] numbers = { 1, 2, 4, 6, 8, 11 };
foreach (int j in numbers)
{
ps.Getfunction(j);
System.Console.Write("{0} ", j);
}
}
i pass the above city id using for each, then pass into the Getfunction.
but in the below only it iterates only the last value 11 in the J
cmd.Parameters.Add("@par", SqlDbType.Int).Value = j; (11)
what is the mistake in my above code
Reply
Answers (
2
)
how to reverse string without using predefined function
One Database connection for all windows forms