DataSource Controls :: Reading Data From An SQL Query C#?

Feb 26, 2010

I don't know how to read data into variables from a SELECT query. I can add, update, and delete queries with no issues. I have browsed a few books, but everyone uses a different approach. Suppose I want to to run a query and 1 record is returned. How do I get the values into my variables.

Suppose my table name is "Job Orders", and the row returned has these 3 fields:

JobNumber, FirstName, Lastname

[Code]....

[Code]....

this is where I go blank ?

"I learn by doing, not by reading"

View 1 Replies


Similar Messages:

Forms Data Controls :: Reading And Paging From Datasource?

May 16, 2010

I have a form with several controls. I'm trying to read from database and navigating through single record per page. I'm displaying a single record but not navigating through. My customerID field is the primarykey. But there are gaps btw records (1,2,5,6,10...etc). Some of them were deleted.

myPage.aspx:

<%@ Page Language="VB" Debug="true" CodeFile="customer.aspx.vb" Inherits="customer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title></title>
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
Customer ID: <asp:Label ID="lblCustomerID" runat="server" ></asp:Label> <br />
Customer Name : <asp:Label ID="lblCustomerName" runat="server" ></asp:Label><br />
<asp:Button ID="btnPrev" runat="server" Text="Prev" OnClick="Prev_OnClick"/>
<asp:Button ID="btnNext" runat="server" Text="Next" OnClick="Next_OnClick"/>
</form>
</body>
</html>

code-behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myReader As SqlDataReader
Dim myConnection = New SqlConnection("server=myPCSQLEXPRESS; database=CustomersDB; uid=myPC est; Password=; Trusted_Connection=yes")
myConnection.Open()
Dim myCommand = New SqlCommand("SELECT * FROM Customers", myConnection)
Dim intFirstRecord As Integer = CInt(myCommand.ExecuteScalar())
myReader = myCommand.ExecuteReader()
If myReader.Read Then
lblCustomerID.Text = myReader("customerID")
lblCustomerName.Text = myReader("CustomerName")
End If
myReader.Close()
myConnection.Close()
currentRecord = lblCustomerID.Text
End Sub

Sub Next_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myCommand As SqlCommand
Dim myConnection As SqlConnection
Dim myReader As SqlDataReader
myConnection = New SqlConnection("server=myPCSQLEXPRESS; database=CustomersDB; uid=myPC est; Password=; Trusted_Connection=yes")
myConnection.Open()
myCommand = New SqlCommand("SELECT TOP 1 customerID, CustomerName FROM Customers WHERE customerID > @customerID", myConnection)
myCommand.Parameters.Add("@customerID", SqlDbType.Int, 5).Value = currentRecord
myReader = myCommand.ExecuteReader()

If myReader.Read Then
lblCustomerID.Text = myReader("customerID")
lblCustomerName.Text = myReader("CustomerName")
End If
myReader.Close()
myConnection.Close()
End Sub

I'm being able to read first record. If I click Next button, my page goes to next record for only once. If i click several times, nothing happens. Does not go to next available records.

View 8 Replies

DataSource Controls :: Reading A Huge File From Data Base?

Oct 19, 2010

I have a 1.5 GB file into a table. I want to read It from server and create a file stream with it for save.

When I use DataAdapter.Fill(DataSet); code OutOfMemoryException occurs.

What should I do for read a hage file from data base?

View 8 Replies

DataSource Controls :: Reading Data From Stored Procedure To Datatable?

Jan 20, 2010

I'm using asp.net 3.5 inc#.

How can I read the data from a stored procedure in Sql Server into a datatable using a datareader.

View 4 Replies

DataSource Controls :: SqlDataSource And Parameters Query / Trying To Accomplish Is Building Dynamic Query

Aug 22, 2010

1. I have a GridView on my page and it uses sqldatasource with parameterized query. What I want to do is, on page load (where nothing has been selected so no parameter supplied), I want it to query everything (something like SELECT * FROM [this_table]) but since my SelectCommand is something like

SELECT * FROM [this_table] WHERE [this_column] = @someParameters AND [that_column] = @someParameters.

Can I play around with default value to achieve something like that but how ? Now, when the page loads, it doesn't show anything (No Gridview).

2. On my page, I made something like (username, gender, address, and more) and one single search button. That means, no single control enable auto postback. What I am trying to accomplish is building dynamic query

(if username specifed -> SELECT * FROM [this_table] WHERE [username] LIKE @username).

If both username and gender are specified (SELECT * FROM [this_table] WHERE [username] LIKE @username AND [gender] = @gender) and you know the rest. How can I do this using GridView and SqlDataSource ? To my knowledge, I can only specify one SELECT statement in a sqldatasource.

View 11 Replies

DataSource Controls :: Update Query Not Working When Using Query Builder To Configure Table Adapter

Jan 15, 2010

[code]...

This query works perfectly on the query analyser.

But when configuring the Table adapter ,I try executing the query and i get 0 rows affected.

What could I be getting wrong in this case.

NB:Existing GalleryID has been supplied.

View 1 Replies

DataSource Controls :: Can't Find Query's / By Right Clicking On Database Created A Query In Server Explorer?

May 17, 2010

By right clicking on my database i created a query in server explorer. But where are this query stored can't find them back. I should aspect that their is a folder query's like there is a folder tables but this isn't the case.

View 10 Replies

DataSource Controls :: Query Over Two Data Sources?

Jan 12, 2010

I need to create a query which does a join between two tables which are in different databases. I can easily connect to each database, and write queries in each, however, I can't seem to find a way of generating a query which does a join between two tables from different databases.

View 2 Replies

DataSource Controls :: Reading Information From Database?

May 16, 2010

I would like to check my database for to see if a user name is available but my script isn't working.

I am taking input from a text box call unametextbox and i'm trying to extract any matching username from the database, this is my code.

[Code]....

View 8 Replies

DataSource Controls :: Reading SQL Schema Information?

Apr 27, 2010

I have a C#/Asp.net web application which caches SQL DB schema information. Is there a way that I can determine what child relationships a given table has? I have looked into using the DataTable.ChildRelations property, but it is never populated with items unless i manually create a relationship using the .add property. I also have access to DataColumn information for each column in the database.

View 4 Replies

DataSource Controls :: How To Convert Sql Query Into Linq Query

Mar 10, 2010

select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid

View 5 Replies

DataSource Controls :: Accessing FK From A Query Via Entity Query

Jan 21, 2010

I've got a query such as

Dim MediaQuery =
From m
In dB.DOWNLOADS _Where m.ID = id _Select

which returns a record from the database. One of the fields in the record is a FK to another table. I need to read this value to be able to set a dropdown based on the ID but I can't work out how to access it. For a standard record I can just do the following txtTitle.Text = MediaQuery.FirstOrDefault().TITLE

However with the foreign key it doesn't work like that. I've tried drpGroup.SelectedIndex = MediaQuery.FirstOrDefault().DOWNLOAD_GROUPS.ID where DOWNLOAD_GROUPS is the FK field but it returns Object reference not set to an instance of an object. If you're simply wanting to read some values from a single db record in the entitiy framework and one is a foreign key how should I go about getting the value?

View 2 Replies

DataSource Controls :: Sum Data From Two Columns In Different Tables - SQL Query

Feb 9, 2010

I am trying to create an application in which there is a summary of outstanding payments.

One table is Table_Bills.

The other table stores records of Payments made and is called Table_Payments.

In summary i want to show 3 figures - each in separate one field datagridview with a data_source in separate data_adapter:

1) Ammount_Due 2) Amount_Paid 3) Balance.

The first two are no problem but the last is giving me a headache.

I tried this:

SELECT SUM(DHB_New_Jobtable.DayWage) - SUM(DHB_Payments.Ammount) AS Expr1

View 4 Replies

DataSource Controls :: Need To Check To See If Any Data Has Been Returned From The SQL Query?

Apr 15, 2010

I am trying to run the following SQL query

string strConString = ConfigurationSettings.AppSettings[ "conString" ];
myConnection = new OdbcConnection(strConString);
myConnection.Open(); // open connection
string strSelect= "select * from tbl_howells_product_data where title like" + "'" + strsearch + "%" +"'" + "order by product_id asc";
OdbcCommand myCommand = new OdbcCommand(strSelect, myConnection);
dtrReader=myCommand.ExecuteReader();

The problem is I need to check to see if any data has been returned from the SQL query, if there are no rows/ data returned by the query then I need to display a message to say that there aren't. I know that there isn't a 'number of rows method' for the dtrReader, so does anybody know how I could do this?

View 3 Replies

DataSource Controls :: Reading / Storing Values Of Checkboxlist In SQL (VB)

Sep 22, 2010

I'm trying to store multiple selected checkboxes from a single checkboxlist, but i don't know where to start. Imagine i have three tables: tbl_events, tbl_organisors and tbl_settings and i want to store the organisors of an event. Each event can have multiple organisors, so each organisor should be added as a single row into tbl_settings. I know how to bind tbl_organisors to a checkboxlist, but how do i store the results (meaning: add the rows to tbl_settings) ?

tbl_events: Event_ID (PK) and Event_Name
tbl_organisors: User_ID and user_name.
tbl_settings: Settings_ID (PK), Event_ID and User_ID

Checkboxlist:

[Code]....

SQLDatasource:

[Code]....

Initially all checkboxes will be unchecked, but users must be able to select multiple organisors from the checkboxlist and then store them into the DB by submitting a form. So the query will look something like: INSERT INTO tbl_settings (user_id, event_id) VALUES (@user_id, @event_id). And this is where my head cracks

1) How do i loop through all selected checkboxes and store each value (user_id) in a new row in tbl_settings?
2) After saving, the users reloads the page and the organisors he just selected must be selected by default in the checkboxlist. How?

View 2 Replies

DataSource Controls :: SSIS Package Not Reading Configuration

Mar 2, 2010

The short story is, I'm developing an SSIS package to select from a remote Oracle database (read: no Windows Authentication) and store into an SQL Server db. I can execute the package just fine in development and after importing, but when I run it as a scheduled job, I get an ora-01017 error (bad un/pw). The details are, I built this package and tested in in BIDS but came across the problem that BIDS really doesn't save the password I'd set for the Oracle connection. After poking around a bit, I found this

[URL] which showed how to create an XML configuration which the package could then read. Fiddled around with that, got it working in BIDS. Connected to Integration Services on the server on which I want to run the package, imported it, right-clicked and did the "Run Package" option as a test, it works great. However, when I connect to the same server's Database Engine to create and schedule a job, I cannot connect to Oracle. For some reason, it seems as if the package is not reading the configuration when run in schedule.

I've tried removing the job and re-working it, thinking maybe it didn't pick up the new version when I re-imported the package. A new job had the same problem. Next, I tried re-naming the .dtsConfig and doing the "Run Package" option as a test. Failed with the same error. A bit surprised, I thought I'd get some kind of file error and we wouldn't get as far as trying to talk to Oracle. Anyway, thinking maybe it's permissions on the configuration, fixed the .dtsConfig name and gave full access to Everyone. That ought to let the Agent see it. Scheduled up the job, still can't talk to Oracle. So it seems as if the scheduled version is ignoring the configuration. Anyone have any idea what I'm missing, that scheduling an SSIS package makes it act differently than running it manually? BTW, the instance under which we're running the package is VS 2005. BIDS 2005 to build the package.

View 3 Replies

DataSource Controls :: Uploading / Reading Of Excel 07 Files?

May 10, 2010

I'm able to upload and read any excel file to my server prior 2007, when I try an 07 Excel file, i'm getting the following error message:

'microsoft.ace.oledb.12.0' provider is not registered on the local machine'

do I need anything specail on the web server to allow for Excel 07 files? I'm running IIS6 and a Win 2003 server

View 1 Replies

DataSource Controls :: Reading Excel Files Through Application?

Mar 16, 2010

iam Working on Asp.net Web apliation using c#.net, in system folder (Ex: E://Santhu) i have few Flat files and Excels Files .So My Application should read those files automatically and should store the data into my database..

View 1 Replies

DataSource Controls :: Reading With DataReader Into List And OutOfMemoryException

Sep 23, 2010

I'm Using a DataReader to Read about 100,000 records, my code look like :

[Code]....

I have a per row computation in reading the rows on GetMyType2Info() method, and this method also another method that I return only one record by ExecuteReader(). the problem is that when the MyTypeList (List<T>) has about 21,000 Items of MyType (<T>) System.OutOfMemoryException is thrown. wanted to know how to resolve this and wanted to know more about the maximum size of List<T> capacity. in addition the execution of the main Query with 100,000 records take about 4 seconds in SQLServer a record has only types of nvarchar , float,datetime and int

View 1 Replies

DataSource Controls :: Reading Datetime - Write It To Another Database?

Jun 4, 2010

I have a record created date stored as" 2010-05-16 15:44:18.700" in sql server database. When I read this date it gets converted to "5/16/2010 3:44:18 PM" . How should I read it so that I don't loose the ending '700' value so that it gets written exactly to another database.Code for reading the record:

String myConn = ConfigurationManager.ConnectionStrings["DBConnectionString"].ToString();
SqlConnection con = new SqlConnection(myConn);
SqlCommand cmd = new SqlCommand();[code].....

View 12 Replies

DataSource Controls :: How To Write A Query Which Reads Data From Optional DDL's?

May 5, 2010

I have couple of DDL's which let user choose couple of different values from it. Once the user has made his selection he clicks on the "Submit" buttion which redirects the user to the other page, which then displays table from backend SQL DB. The pages are named Page1.aspx and Page2.aspx resp. I am using Querystring to carry forward the values of the DDL's to Page2.aspx.

How can i modify the query in such a way that even if one of the DDL's is left blank the Query would ignore that and shall produce the table considering value of DDL2 in the where clause. In case both the DDL's are empty then the query will not have a where clause and shall showcase the complete table as such. I've written a query for this but it's not working the way it shoul.Here is my code for the SQLDataSource: [Code]....

View 3 Replies

DataSource Controls :: Select Query / Not Filtering Data From Database?

Mar 19, 2010

i have used one query like this

Select skillReq from tblPostJobs where SkillReq like '%Silverlight 2.0%'

it is working fine. But while giving

Select skillReq from tblPostJobs where SkillReq like '%Silverlight 2.0,C#%'

It is not filtering data from database. It is only checking starting and ending Character.In my database some keyskill are like that

Asp.net 3.5,4.0,C#,Sql server 2008,Silverlight 2.0,3.0.

My requirement is to check each word in "SkillReq" text.

View 3 Replies

DataSource Controls :: LINQ To Entity Query - Getting Data From The RDBMS

Jan 1, 2010

if LINQ to Entity queries the EDMX class or its .CSDL or SSDL XML on its way to getting data from the RDBMS?

View 8 Replies

DataSource Controls :: Select Query For Retrieving Data Between 2 Dates?

Jan 8, 2010

I want to create an application where I need to enter date to the ms access database.

I am a bit confused regarding how to make the user to enter date. The options avaliable are:

a. Shall I use a textBox?

b. Shall I go for 3 drop down lists?

or something else.

Some more questions:

1. what date format shall i use? (dd-mm-yyyy, dd-mmm-yyyy, etc, etc or anything else)

2. What datatype shall i use to store the date in the database?

3. What SQL query shall i use to retrieve the data between 2 dates?

let me know if there are multiple options available regarding this application.

I want to make this application as easy as possible for the user.

View 4 Replies

DataSource Controls :: Binding A Complex Query To A Data Control?

Apr 21, 2010

I'm trying to implement a recipe search page that allows users to specify search criteria by selecting checkboxes that match desired recipe attributes. All the data is stored in a database uing tables with 1 - many relationships. Each recipe can have multiple attributes from any of 5 attribute tables. I want to find all the recipes that match the user-selected criteria and display them in a grid. For example, the user may want a breakfast (attribute 1) recipe that is made with fruit and milk (attributes 2 and 3), is low-fat and high fiber (attributes 4 and 5), and takes less than 15 minutes to prepare (attribute 6). The query for this example might look something like:

SELECT distinct recipes.name, recipes.difficulty, recipes.preptime, recipes.cooktime

FROM recipes, recipeMeals, recipeDishes, recipeFoodGrps, recipeNutrients, recipeFixTimes

WHERE recipes.id = recipeMeals.recipeId and recipes.id = recipeDishes.recipeId and recipes.id = recipeFoodGrps.recipeId and recipes.id = recipeNutrients.recipeId and recipes.id = recipeFixTimes.recipeId and recipeMeals.mealId in (1) and
recipeDishes.dishId in (5) and recipeFoodGrps.fdGrpId in (1, 6) and recipeNutrients.nutrAttsId in (2, 3) and recipeFixTimes.fixTimeId in (1)

I' can generate the SQL but can't figure out how to bind it to a grid control. No could I see how to get any of the data controls to build the query for me. Is there a way to say "execute this query and display the results in a GridView"?

View 4 Replies







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