Binding Different LINQ Datasource Using Same Variable With If Statement?

Nov 27, 2010

OK So I know WHY I am having the error I am getting. I don't know HOW to fix it. Basically, if the user doesn't have a certain permission, I need to join another table. But .NET is so picky I can't just make two different queries in an IF statement and then use it outside of the if statement. I can think of some ugly work arounds for this, but I would rather not. I am fairly new to .NET I know just enough to be dangerous.

[code]....

I get the error: Unable to cast object of type

'System.Data.Linq.DataQuery1[VB$AnonymousType_111[System.Guid,System.String,System.String,System.String,System.String,System.Nullable1[System.DateTime],System.Nullable1[System.DateTime],System.Nullable1[System.Guid],System.Nullable1[System.DateTime],System.Nullable1[System.Guid],System.Nullable1[System.DateTime]]]' to type 'System.Collections.Generic.IEnumerable`1[Ten11CRMLib.Company]'.

because of this: Dim l As IEnumerable(Of Company) its not just IEnumerable of a Company, its got the source in it. I have to explicitly select source to use it in my datagrid. Can I make Dim l something that will make it stop complaining?

View 2 Replies


Similar Messages:

DataSource Controls :: Using A Variable As A Parameter In A SQL Statement

Mar 25, 2010

I've done some SSIS package work in the past, but am by no means an expert.

I want to use an SSIS package to do the following:

1. Get the file name of the newest file in a windows folder (using a filename template like his: filename_ *.txt where the * part is always a date in the format of yyyy-mm-dd.

2. Use that file name in later portions of the SSIS package by reading the file and transferring data from it to a SQL table using a Data Flow task.

and use the result (which should be the name of the newest file) to open that file and pull data out of it and into a 2nd SQL table. I admit, I'm not sure how to use the dynamic result of this SELECT query as the file name in a flat file connection manager.

View 6 Replies

DataSource Controls :: How To Declare Variable From SQL Statement

Oct 21, 2010

I am rather confused as how or where to declare this variable in asp.net.

[Code]....

Whenever i put this in my sqldatasource for it is asking me to Define Parameters:

The wizard has detected one or more parameters in your SELECT statement. For each parameter in the Select Statement, choose a source for the parameter's value.

View 4 Replies

DataSource Controls :: Unable To Use Session Variable In Sql Select Statement

May 26, 2010

I am new to all this, and ignorant beyond compare. I believe I have the same problem as this :

[URL]. However, the solution proposed for him doesn't seem to work for me. I have a session variable that 'march_cpi_session' that I wish to include in an sql select statement to multiply the values I get from a datatable before they're used to populate a gridview control. The session variable works fine elsewhere in my application, but causes a variety (depending upon how I fiddle about with the syntax) of sql errors. This is the currrent code:

[code]....

View 3 Replies

C# - SQL Statement Transformed TO LINQ - How To Translate This Statement To A Working Linq

Mar 5, 2010

I am having trouble with this I have 3 Data tables i use over and over again which are cached I would like to write a LINQ statement which would do the following is this possible?

T-SQL VERSION:

SELECT P.[CID],P.[AID]
,B.[AID], B.[Data], B.[Status], B.[Language]
FROM MY_TABLE_1 P
JOIN
(
SELECT A.[AID], A.[Data], A.[Status], A.[Language] FROM MY_TABLE_2 A
UNION ALL
SELECT B.[AID], B.[Data], B.[Status], B.[Language] FROM MY_TABLE_3 B
) B on P.[AID] = B.[AID]
WHERE B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1 AND B.[Language] = 'EN' OR B.[Language] = 'ANY' AND B.STATUS = 1

Then i would like it to create a result set of the following

Results:
|CID|AID|DATA|STATUS|LANGUAGE

View 3 Replies

DataSource Controls :: LINQ Statement Can ShowTime In The DB

Apr 5, 2010

[Code]....

I must have a LINQ Statement does i can show if my Time in the DB <= as the Time where i become from my Session +60 Minutes ??

View 3 Replies

DataSource Controls :: Update Statement Using Linq To SQL?

Jun 22, 2010

I have a method to execute two "Update" sql statements.

The first one works fine and the second one I can't get to work for nothing.

Here is the entire method:

[Code]....

The error I am getting is "Incorrect syntax near '05'."

It is occuring on the next to the last line which is:

dc.ExecuteCommand(sql);

I update the variable "sql" first so I can debug. At the time it crashes the value of sql is:

"Update Blogs set Status = 'Archived', ArchiveDate = 06/22/2010 05:14:46 PM Where (BlogID != 1) and (Status = 'Published') and (AuthorID = 9e37e028-c205-4903-920e-e8643b30a724)"

It appears to be the ArchiveDate that is causing the problem here. The "05" is the hour of the time portion. Both ArcgiveDate and PublishDate are defined exactly the same in the database. If you look at the first dc.ExecuteCommand it does exactly the same
thing with PublishDate (DateTime column) in the same table and it works just fine.

Then I modifed the code and remove the ArchiveDate from the sql statement then I get the error:

"Incorrect syntax near 'e028'."

which as you can see is part of the AuthorIDs value in the where clause. So I am assuming both the date and the Guid / Author ID is causing problems. I have tried enclosing the values in quotes but I just cant make this work even though it seems to be working fine in other places.

I even remove the code for the author ID and left in the code for the ArchiveDate and it still does not work so I have proved that both are causing a problem.

View 1 Replies

DataSource Controls :: Run A Single Select Statement And Store The Resulting Value In A Variable?

Jan 28, 2011

I need to run a select statement on log in event and store the value of the select statement (returning one item) in a session variable.Do I have to u sqldatasource for this.. or is there someway I can run a single select statement and store the resulting value in a variable?

View 7 Replies

DataSource Controls :: Linq - Update Statement Where Clause?

May 25, 2010

I am using Linq to SQL. Tables have timestamp columns and I am using regular Linq methodology in ASP.NET MVC.I do use detached entities and always try to do updates without first querying the database for the original entity. To update an entity I use context.Attach(entity, true) followed by context.SubmitChanges() and all is fine. The sql statement that gets executed looks like:

[Code]...

View 7 Replies

DataSource Controls :: Runtime Compilation Error CS1026 When Use Linq Statement?

May 5, 2010

We have an application developed on VS2008 [Asp.Net & C#], in this application we provide the facility to the user to write his/her business logic code. For that purposes we maintained a Businesslogic.cs file where user can write his/her code and our application build it as a BusinessLogic.dll file at runtime.

But the problem is when we introducing Linq statement/code into the BusinessLogic.cs file then it generated compilation error [CS1026 ].

Note that, when we build the dll from VS2008 environment then it working fine with the same code which we write into the BusinessLogic.cs & don't generated any compilation error.

View 8 Replies

DataSource Controls :: View The Linq Variable Data In C#?

Mar 9, 2010

I wrote a linq code to read from database if its value is equal to textBox that user enters.

I dont wanna show the result in Gridview,so jz I wanna use that value. The code I wrote is

var sql = from x in db.Managers
where x.M_Name == TextBox1.Text.ToString()
select x.M_Name;

in this code I'm selecting only the name that user entered in textBox

so i want to do like tis

String Name = sql.ToString();

means to store the value in string. so the problem is i can not assign the var to string.

View 2 Replies

DataSource Controls :: Create A Multi Column Listbox By Combining Fields In Linq Select Statement

Jan 11, 2010

I am trying to create a multi column listbox by combining fields in Linq select statement, as Let Name = Last + First. The problem is how to pad the Last column with spaces as you would in SQL using REPLICATE so when I bind the listbox to the data, it looks like two columns.

View 5 Replies

Why Can't Set A Variable Within An If Statement And Use It Outside

Feb 24, 2011

Why can't I set a variable within an If statement and use it outside? The following doesn't work - in the last line - variable unassigned???

[Code]....

View 2 Replies

How To Use A Variable From My Code In A SQL Statement

Mar 9, 2011

I'm converting a string to integer and than inserting this integer in my post table.

int currTopicID = Convert.ToInt32(id.Text);
SqlCommand cmd = new SqlCommand("INSERT INTO post VALUES(currTopicID)", con);

The problem is that currTopicID isn't being recognized as an integer when i do the insertion.

View 4 Replies

SQL Server :: Using Session Variable Value In An Insert SQL Statement?

Jan 7, 2011

This should be really simple and I am new to asp development.

I am using ASP log in controls..when user logs in, I am storing the userid in a session variable. On this another page, I want to put the previously stored session variable value into a table using Insert statement.

in my sqldatasource..here is the code..

InsertCommand="INSERT INTO tblMain(PatientId, UserId, IncAge, IncDeNovo, IncAnginaIschemia, IncNative, IncLesions, IncStudyConform, IncStenosis) VALUES (@PatientId, @UserId, @IncAge, @IncDeNovo, @IncAnginaIschemia, @IncNative, @IncLesions, @IncStudyConform,
@IncStenosis)">

View 2 Replies

Forms Data Controls :: Manually Binding GridView With SQL Statement.?

Feb 9, 2010

I have a gridview that I am manually binding in my code behind page because I have to pull out information from other sources for the WHERE clause.The issue is that I get an error on the aspx page that one of the columns is not in the dataview, however when I run the SQL statement in SQL all the columns are there and there is not a spelling error.If I remove the column from the gridview then the page loads.I cannot see why the column is a problem.Here is my ASPX gridview code.

[Code...]

This is the line where the error occurs. <asp:Label ID="Label2" runat="server" Text='<%# Bind("date_submitted") %>'></asp:Label> Here is the code behind

[Code...]

Here is the ending SQL statement that works in SQL and does return the date_submitted column. SELECT id, title, date_submitted, (SELECT username FROM users WHERE (id = t.submitted_by_user_id)) AS submitted_by, (SELECT name FROM departments WHERE (id = t.department_id)) AS department FROM tickets AS t WHERE (closed_by_user_id IS NULL) AND (department_id = 48 OR t.department_id = 83) ORDER BY t.date_submitted DESC



View 2 Replies

C# - Binding List Variable One After Another?

May 13, 2010

this is my class

[code]....

hope my Question is clear.

View 2 Replies

Forms Data Controls :: Storing Eval Value In A Variable Or IF Statement?

Jul 8, 2010

How do I store an Eval in a variable or use the value of the Eval in an if statement?

View 5 Replies

Forms Data Controls :: Gridview : Working With A Variable In A SQL Statement?

Mar 21, 2010

On Page1 of a project, I have a Gridview showing a table of customer names (showing CustID, CustName, CustJoinDate). When I click on a record, I have passed a querystring to Page2 showing an address table for that customer. This part works for me.

The SQL statement in simply: Select * from CustAddress where CustID = @cust

What I would like to do though, is capture that @cust to a session variable so that I can use it later on.

View 2 Replies

LINQ Statement Vulnerable To SQL Injection?

Sep 29, 2010

Is this LINQ statment vulnerable to SQL injection?

var result = from b in context.tests
where b.id == inputTextBox.Text
select b;

where context is an Entity and tests is a table. I'm trying to learn LINQ and I thought that the benefit of it was that it wasn't vulnerable to sql injection, but some stuff I've see has said differently. Would I need to parametrize this LINQ statement to make it safer? If so, How? Also would this be considered linq to sql or linq to entities?

View 6 Replies

C# - Join Is Not Working In LINQ Statement?

Mar 23, 2011

I am new to LINQ. I have a GridView which I am populating using LINQ. My LINQ statement is taking query string from previous page. The query string is in string format. Here is the code:

protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];

[code]...

View 3 Replies

C# LINQ Joining And Where Statement Not Working?

Mar 5, 2010

I am trying to have the collection of order IDs be used in my where statement how come i can't get this to work?

List<int> orders = new List<int>(){1,2,3,4,5};
DataTable dtTable1 = getOrders();
DataTable dtTable2 = getOrderDetails();
var results = from a in dtTable1.AsEnumerable()
join b in dtTable2.AsEnumerable() on a.Field<int>("ID") equals b.Field<int>("ID")
where orders.Contains(b.Field<int>("OrderID"))
select a;

View 2 Replies

ADO.NET :: Conver The Following SQL To LINQ Statement For Method?

Mar 4, 2011

have following method which returns "List"

public List<DistributionGroup> GetDistributionGroupsByUserId(Guid userId)
{
return (from dgu in db.DistributionGroup_Users where dgu.UserId == userId select

[code]...

View 3 Replies

ADO.NET :: Possible To Generate Dynamic LINQ Statement?

Nov 29, 2010

Is it possible to generate dynamic LINQ statements? I need to be able to build conditional "WHERE" clauses for some of my LINQ statements. I don't want to write a giant block of code to hand every possible combination of filters, sorts and groups. I found a article online that outlines how to use string based where clauses here. Does LINQ in framework 4.0 no longer support this? Every example I've found has giant walls of virtually unreadable, must likely unmaintainable code.

View 1 Replies

C# - GridView Not Populating From LINQ Statement?

Mar 23, 2011

I have a GridView which is not bound to any DataSource. In my page load event I am writing this code:

protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int16.Parse(getEntity);

[Code]....

Now I can see the the value is coming from previous page, but my GridView is not populating anything. What I am doing wrong here?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved