Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

c# and sql

I have c# 2005 and sql 2000. I am able to open through a wizard the sql views and see the results. I want to be able to pull the data that are grabbed from the views into my application.

I really did not want to write a command.commandtext = "select....."

statement. Is there a way to call the query as itself from sql instead of actually having to rewrite the query in c#?
0
bman9111
Asked:
bman9111
  • 6
  • 5
  • 3
  • +1
1 Solution
 
ozymandiasCommented:
"call the query as itself" ?

I'm not clear.
The only way to get the data is via a command and that command must have some text.
The command text can be any sql such a selecting from a table, selecting from a view, calling a stored porcedure or user function, but you have to execute a command somewhere.
0
 
strickddCommented:
the best way to do this is either

A) Use a table adapter to the View

B) command.commandtext = "SELECT * FROM ViewName"
0
 
bman9111Author Commented:
I guess i am not wanting to have to take a view I did in sql 2000 and have to retype it and redo the syntax for it in order for my application to grab the data.


Is there a way to just be able to call a view without rewritting it?

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
strickddCommented:
you select from the view itself. A view is created dynamically in SQL as the data updates. It acts as a table would and you can select from it just as if it were a table.
0
 
_TAD_Commented:

Yes, you can create a SQL View(which will act like a data table), or you can create a stored procedure that returns a query result.

SQL Views become very important when working with highly-normalized databases.

0
 
_TAD_Commented:

Yes, you can create a SQL View(which will act like a data table), or you can create a stored procedure that returns a query result.

SQL Views become very important when working with highly-normalized databases.

0
 
_TAD_Commented:

Yes, you can create a SQL View(which will act like a data table), or you can create a stored procedure that returns a query result.

SQL Views become very important when working with highly-normalized databases.

0
 
strickddCommented:
I'm glad to see you are consistent with your responses...
0
 
bman9111Author Commented:
so basically what ever view I created in sql I need to take the code and insert it into a commandtext = "select.....what ever i wrote in sql"

correct?
0
 
bman9111Author Commented:
let me restate this...
I have a view that is called table1view

how can I call this in c#?
0
 
ozymandiasCommented:
select * from tableview1
0
 
ozymandiasCommented:
...that is the CommandText of the Command.
You call it the same way you would in SQL.
0
 
bman9111Author Commented:
I have a query called tableview1 and when I try to do a select * from tableview1 I get an invalid object error.

I tried other views but the only thing I can query is the tables.
0
 
_TAD_Commented:

Are you using Oracle?  In oracle, after you create a view, you need to create a public synonymn as well.
0
 
_TAD_Commented:
nevermind...   "I have c# 2005 and sql 2000"

I suspect the db account that you are using to access the database has been granted specific access to various tables.

You should be sure that the db account that you are using to access the database has the data_reader role so you can query any object.


Using the account that you are using for your application, execute the following queries:


-- User Tables
Select * from systemobjects where xtype='U'

-- User Views
Select * from systemobjects where xtype='V'

0
 
bman9111Author Commented:
I tried that

commandtext = "Select * from systemobjects where xtype='V'"

and got an error:

"Invalid object name 'systemobjects'"

this is the same error I get trying to call the other view.

also for the heck of it I tried.

Select * from queryname where xtype='V'
0
 
_TAD_Commented:

systemobjects is a SQL Server table that contains all of the objects needed in order for SQL server to function.

In short, systemobjects *definately* exists and you simply don't have access to it.  


Your problem is security.  The user that you are using to access SQL Server simply does not have sufficient privledges
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now