returning one row and actuallying getting data from it.

i don't want to do this via grids or any of that.  that's the one complaint i have of, everyone wants to return data in these dang grids and all i want to do is run a query and extract the data i want.

i already have the query:

FROM tblUsers
WHERE (txtUsername = @username)

i just need to know how to get the resultset and get the value of the intUserID column and assign it to a variable.
12/8/2004 12:38:58 AM 16182 articles. 0 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 34

read the MSDN documentation about SQLCommand.ExecuteScalar() Method.  They have some sample code too.

Dinakar Nethi
Life is short. Enjoy it.
12/8/2004 4:09:45 AM
quite honestly that does not help.  i'm very new to c# which is why i'm posting on here for help.
12/8/2004 4:45:09 AM
its very simple..any article over the web about executescalar() method would have enough sample code/xplanation for you to understand...

dim your sqlcommand vairable..set the commandtext property as shown your connection ..xecute your sql..close your connection..

cmd.CommandText = "select count(*) from region";
'open the connection
Int32 count = (int32) cmd.ExecuteScalar();
'close the connection

or is there something else that you are trying to do ?
Dinakar Nethi
Life is short. Enjoy it.
12/8/2004 3:38:22 PM
i suppose you didn't understand my question.  i want to return one row and manipulate the data within that row, which could mean more than one column.  i'm not looking to get the count(*), i'm looking to actually extract data.
12/8/2004 3:53:11 PM
>>i suppose you didn't understand my question

you were right..your sql statement kept misleading me..
you can use a Datareader or DataAdapter...

Dim ConnectionString As String = "Your_Connection_String"
Dim CommandText As String = "select Col1, Col2, Col3 from TableName"
Dim myConnection As New System.Data.SqlClient.SqlConnection(ConnectionString)
Dim myCommand As New System.Data.SqlClient.SqlCommand(CommandText, myConnection)
Dim DataReader As System.Data.SqlClient.SqlDataReader = myCommand.ExecuteReader()
If DataReader.HasRows Then
Do While DataReader.Read()
End If

for DataAdapter..

dim DA2 as SqlDataAdapter = New SqlDataAdapter
dim strcmd as string
strcmd="select col1,col2 from YourTable where userid=@userid"
Dim selectCMD AS SqlCommand = New SqlCommand(strcmd, objcon)
selectCMD.Parameters.Add("@userid", =10
DA2.SelectCommand = selectCMD
Dim DS2 As New System.Data.DataSet()
Dim DT2 As System.Data.DataTable = DS2.Tables(0)
Dim ADR2 as
if DS2.Tables(0).rows.count > 0 then
ADR2= DS2.Tables(0).rows(0)
if not IsDBNull(ADR2("col1")) then
end if
end if

Datareader is faster if you are just displaying data...
Dinakar Nethi
Life is short. Enjoy it.
12/8/2004 4:16:48 PM
that's what i'm talking about!  :)  i won't be able to mess with any code until tonight, but that is just what i was looking for i think.  everyone else just uses grid and i need to do some processing on one column, i never see any code examples for that, but that looks like it is what i need.  thanks so much!
12/8/2004 4:25:37 PM

Similar Artilces:

How do i get one row if the resultset returned has no rows.
Hi I have couple of CTE's which i want to ultimately insert into a temp table... and based on my condition some of the CTE's return some rows and some dont... but i want to have the CTE return atleast one row if there is no data in it.. I have tried doing the following but i am not getting the desired output    ;with cte_rpt4 as (select '4' a,recd_dt as approve_dt, prov_no, prov_name, client_id, claim_mst_id, claim_adj_id, claim_dt, claim_amt, rpt4, (Select count(distinct(Claim_mst_Id)) as crpt4 from #temp1 where datediff(day,isnull(recd_dt,create_dt),isnull(c...

Can't get dw_1.Object.Data[row] for a row > 32768
Is anyone aware of a problem with passing a row greater than MAX(integer) (32768) to dw_1.Object.Data[row]? I would appreciate a response. Jameel Abdo MCI Systemhouse. I understand that PB5 didn't support object notation for more than 32K rows. It was supposed to be fixed in PB6 (although I haven't confirmed it in PB6, myself). The object notation tended to be a tad flakey in PB5 too (poor null handling, etc.). Many developers decided to stick with the GetItem, SetItem in PB5 to avoid these problems. Jameel Stephen Abdo wrote: > Is anyone aware of a proble...

xquery returning one data row result only?
hi folks, i am trying to get 2 values from xml file. the query is only returning one.. code and xml file is below.. Dim myXPathNodeIterator As XPathNodeIterator = myXPathNavigator.Select("/root_node/XML_Child_Node/PDT_NO[@p_family='" & prVal & "']/@pdt_des") While (myXPathNodeIterator.MoveNext()) If myXPathNodeIterator.Current.Name = "PDT_NO" ThenMe.PDT_cmb.Items.Add(New WebControls.ListItem("aaa", myXPathNodeIterator.Current.Value)) 'Me.PDT_cmb.DataTextFiel() End If End While myXPathDocument = Nothing  <XML_Child_...

How to get three rows of data combined into one?
I'm trying to select a list of employees from the tEmployees table and join that to a Newsletter Subscription Table.  Each employee is in the tEmployees table once, but the employee's ID can be in the tNewsletter table multiple times, as they can subscribe to multiple newsletters.  So, one employee is returning as many rows of data as they have newsletter subscriptions.  Is it possible to some how group or merge this data, so taht each employee only has one row of data, with a column for each newsletter they subscribed too?  Never make important decisions on a Mon...

Displaying one of the columns in GridView data as GroupBy or similar data one after another row
Hi Would like to know the property or code that will Group data in one of the columns of GridView together. In other words i like to display the columns data in GridView that is repeated more than once together. Example: say Column heading Name John Jim Kevin Albert John Jim John You can see john or jim is displayed in Name Column at various rows. I like to get them displayed together such as John John Jim Jim Regards,-- "Mark As Answer" if my reply helped you -- Hi I am not too sure, but may be you can try a "Order by" clause at your SQL level. Say,...

Get differant rows from db and return one SqlDatareader?
I need to get several rows from db in one SqlDatareader. How do I do that? This is my procedure: CREATE Procedure hentEnkeltVare ( @varenr int ) AS SELECT v.navn, v.enhed, vt.navn as type, v.pris, v.billedNavn FROM vare as v,varetype as vt WHERE v.type=vt.typenr and varenr=@varenr GO And with this method I can get one row from db: public static SqlDataReader hentEnkeltVare(int vareNr) { SqlConnection sqlConnection = Util.Connect(); SqlCommand s...

How do I find the number of rows returned in an Object Data Source
Hi,Does anyone know how to find out how many rows have been returned when an Object Data Source has been bound?Thanks.  I believe you'd use the selecting event handler - like this:     protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)    {        bGetSelectCount = e.ExecutingSelectCount;    } Take a look at parameter 'e' in the Selected event of the ObjectDataSource. The ReturnValue should give you the datatable/dataset you're about to b...

DetailsView and getting data from a row or field?! VB.NET
I am using Visual web developer and ASP.NET 2.0 using VB.NET Basically i have a detailsview which is bound to a database. It has two rows which are User and Status.. E.g. User   : Sean       Status: OnlineNow the trouble is that i wish to get the data of the User row and insert it back into another database, dont worry the SQL is not my problem..What i need help with is getting the data that it is in that row! I can get the selected page index but not what i need! Also if you know how to do this uding the grid view, form view or any data repr...

How to get data from database row by row
I try to get data from a database row by row, I am using DataReader, the return result is not I expected, don't know how to solve it. Here is my sample code: --------------------------------------------Dim commandText As String = "select * from customer "Dim con As New OleDbConnection("Data Source=c:\company.mdb;Persist Security Info=False; Provider=Microsoft.Jet.OLEDB.4.0;")Dim Cmd As New OleDbCommand(commandText, con)Dim reader As OleDbDataReader = Cmd.ExecuteReader()             Using con       &nbs...

Get Access to actual Data Object from FieldTemplate, when using DynamicObjectDataSource
Hi There, I am using the DynamicObjectDataSource with Dynamic Data to scaffold my data-bindable business objects using controls such as Detailsview etc. In one of my custom field templates I want to populate a drop down list of string values. These values are returned by calling a string[] method on my bound class.         public override string[] GetChoices(string fieldName) {            return new string[0]; // TODO: This contains a switch statement which returns a string array based on the field...

How to get data from an Object data source?
Hi I am new to data source controls and I have a basic query...I am using following code to show some results in a GridView with custom pagination.<asp:ObjectDataSource ID="objectDataSourceSearch" runat="server" EnablePaging="True"              SelectMethod="Select" TypeName="GoogleSearchDatasource" SelectCountMethod="SelectCount"             OnSelecting="objectDataSourceSearch_Selecting" >  &...

Data of two rows in one row
  Emp-----ID Name1 x1 P2 y2 Q3 WEmp_DataId Name-1 Name-21 x P2 y Q3 wabove is my tables (Emp ),And the I want the Resulting Data in the (Emp_Data) this possible Pls Help........Thanks in advance----- SELECT t.ID,MAX(CASE WHEN t.Seq=1 THEN t.Name ELSE NULL END) AS Name_1,MAX(CASE WHEN t.Seq=2 THEN t.Name ELSE NULL END) AS Name_2FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ID Order BY Name) AS Seq,* FROM Emp)tGROUP BY t.ID Please click "Mark as Answer" if my reply solved your problem.CheersRammohan   Thanx it helped me a lot...

How to move a row in a data table object to the top of the table? The data table is in a data set. The data is bound to a drop down list box.
I am maintaining some 2003 C#/ code for a web application. In the application a table in a data set is usedto populate a drop down list box.(The drop down list box will display a list of names) Before the data set table is bound to the list box control, blank characters are inserted at the topof the data set table. The purpose of this, is to display a blank line in the drop down list box, when the list box isinitially displayed. This code works fine. (See lines 1-14 below). Now I have been asked to modify the source code so that instead of a blank line being inserted at to top of th...

How to edit just one row of a coloumn using object data source??????
MY .aspx code: <asp:Label ID="lblcontactDetails" Width=50% CssClass="labelh3" runat="server" Text="Contact Details"></asp:Label><asp:GridView ID="GVContactDetails" runat="server" ShowFooter="True" AllowPaging="True" PageSize="7" AutoGenerateColumns="False" EmptyDataText="No Entries Found" DataSourceID="ObjContactDetails"> <Columns><asp:BoundField DataField="ContactID" HeaderText="ContactID" SortExpression="ContactID...

Web resources about - returning one row and actuallying getting data from it. -

Is Anyone Buying The Avengers' Box Set thinking They're Actuallying Buying A Rimowa's Topas Case?
The latest example of nutty trademark claims comes from Rimowa, makers of various luxury luggage cases, including the Topas briefcase that has ...

Is Anyone Buying The Avengers' Box Set thinking They're Actuallying Buying A Rimowa's Topas Case?
The latest example of nutty trademark claims comes from Rimowa, makers of various luxury luggage cases, including the Topas briefcase that has ...

Resources last updated: 12/22/2015 2:26:02 PM