Webboy2008
asked on
asp.net c# string and session
Session["UserId"] = PortalGlobals.UserId ;
//string UserId = PortalGlobals.UserId;
For some reasons, if I tried to use //string UserId = PortalGlobals.UserId;
and the following sql. It will fail me....
Any experts have idea how to fix it?
SqlDataSource1.SelectComma nd = "SELECT CrmSchedule.*, CrmSchedule.MeetingCity + ', ' + CrmSchedule.MeetingState as MeetingCityAndState, CrmLeadSource.Description AS DescLeadSource, "
+ " CrmMeetingType.Description AS DescMeetingType, CrmScheduleStatus.Descript ion AS DescScheduleStatus, "
+ " Customers.Name As CustName, Customers.MC_Number FROM CrmSchedule INNER JOIN"
+ " CrmLeadSource ON CrmSchedule.LeadSourceId = CrmLeadSource.LeadSourceId INNER JOIN"
+ " CrmMeetingType ON CrmSchedule.MeetingTypeId = CrmMeetingType.MeetingType Id INNER JOIN"
+ " CrmScheduleStatus ON CrmSchedule.ScheduleStatus Id = CrmScheduleStatus.Schedule StatusId INNER JOIN"
+ " Customers ON CrmSchedule.CustomerId = Customers.ID Where CrmSchedule.UserId='" + UserId.ToString() + "'"
+ " Order By CrmSchedule.BeginDate Desc";
//string UserId = PortalGlobals.UserId;
For some reasons, if I tried to use //string UserId = PortalGlobals.UserId;
and the following sql. It will fail me....
Any experts have idea how to fix it?
SqlDataSource1.SelectComma
+ " CrmMeetingType.Description
+ " Customers.Name As CustName, Customers.MC_Number FROM CrmSchedule INNER JOIN"
+ " CrmLeadSource ON CrmSchedule.LeadSourceId = CrmLeadSource.LeadSourceId
+ " CrmMeetingType ON CrmSchedule.MeetingTypeId = CrmMeetingType.MeetingType
+ " CrmScheduleStatus ON CrmSchedule.ScheduleStatus
+ " Customers ON CrmSchedule.CustomerId = Customers.ID Where CrmSchedule.UserId='" + UserId.ToString() + "'"
+ " Order By CrmSchedule.BeginDate Desc";
protected void Page_Load(object sender, EventArgs e)
{
Session["UserId"] = PortalGlobals.UserId ;
//string UserId = PortalGlobals.UserId;
SqlDataSource1.SelectCommand = "SELECT CrmSchedule.*, CrmSchedule.MeetingCity + ', ' + CrmSchedule.MeetingState as MeetingCityAndState, CrmLeadSource.Description AS DescLeadSource, "
+ " CrmMeetingType.Description AS DescMeetingType, CrmScheduleStatus.Description AS DescScheduleStatus, "
+ " Customers.Name As CustName, Customers.MC_Number FROM CrmSchedule INNER JOIN"
+ " CrmLeadSource ON CrmSchedule.LeadSourceId = CrmLeadSource.LeadSourceId INNER JOIN"
+ " CrmMeetingType ON CrmSchedule.MeetingTypeId = CrmMeetingType.MeetingTypeId INNER JOIN"
+ " CrmScheduleStatus ON CrmSchedule.ScheduleStatusId = CrmScheduleStatus.ScheduleStatusId INNER JOIN"
+ " Customers ON CrmSchedule.CustomerId = Customers.ID Where CrmSchedule.UserId='" + Session["UserId"] + "'"
+ " Order By CrmSchedule.BeginDate Desc";
}
Also, I think that's not quite a well-formed SQL command, line 6 is going to result in:
SELECT CrmSchedule.*, CrmSchedule.MeetingCity + ', ' + CrmSchedule.MeetingState as MeetingCityAndState, CrmLeadSource.Description AS DescLeadSource
Being sent to the SQL server, and those plus signs, quotes and comma aren't gonna make it happy - looks like you might have had some other variable in there, I would recommend writing your SQL statement as:
Or better yet, use SqlParameters (just not sure how to do that off the top of my head with the SqlDataSource, sorry).
SELECT CrmSchedule.*, CrmSchedule.MeetingCity + ', ' + CrmSchedule.MeetingState as MeetingCityAndState, CrmLeadSource.Description AS DescLeadSource
Being sent to the SQL server, and those plus signs, quotes and comma aren't gonna make it happy - looks like you might have had some other variable in there, I would recommend writing your SQL statement as:
string commandText = @"SELECT CrmSchedule.*, CrmSchedule.MeetingCity, CrmSchedule.MeetingState as MeetingCityAndState, CrmLeadSource.Description AS DescLeadSource,
CrmMeetingType.Description AS DescMeetingType, CrmScheduleStatus.Description AS DescScheduleStatus,
Customers.Name As CustName, Customers.MC_Number FROM CrmSchedule INNER JOIN
CrmLeadSource ON CrmSchedule.LeadSourceId = CrmLeadSource.LeadSourceId INNER JOIN
CrmMeetingType ON CrmSchedule.MeetingTypeId = CrmMeetingType.MeetingTypeId INNER JOIN
CrmScheduleStatus ON CrmSchedule.ScheduleStatusId = CrmScheduleStatus.ScheduleStatusId INNER JOIN
Customers ON CrmSchedule.CustomerId = Customers.ID Where CrmSchedule.UserId='{0}'
Order By CrmSchedule.BeginDate Desc";
SqlDataSource1.SelectCommand = String.Format(commandText, PortalGlobals.UserID);
Or better yet, use SqlParameters (just not sure how to do that off the top of my head with the SqlDataSource, sorry).
ASKER
Error:
Compiler Error Message: CS0103: The name 'commandText' does not exist in the current context
Source Error:
Line 24: + " Customers ON salesreps.CUSTOMER_ID = Customers.ID"
Line 25: + " WHERE salesreps.USER_ID='{0}'";
Line 26: SqlDataSource1.SelectComma nd = String.Format(commandText, PortalGlob als.UserId );
Line 27:
Line 28:
Compiler Error Message: CS0103: The name 'commandText' does not exist in the current context
Source Error:
Line 24: + " Customers ON salesreps.CUSTOMER_ID = Customers.ID"
Line 25: + " WHERE salesreps.USER_ID='{0}'";
Line 26: SqlDataSource1.SelectComma
Line 27:
Line 28:
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it. Your point is coming.
Have another question if you interest to help:
https://www.experts-exchange.com/questions/26889448/javascript-asp-net.html
Have another question if you interest to help:
https://www.experts-exchange.com/questions/26889448/javascript-asp-net.html
ASKER
Excellent Helps
How does it fail? What happens, or what exception do you get?