CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.getting_started Tags:
Item Type: Date Entered: 6/24/2006 2:09:22 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 36 Views: 26 Favorited: 0 Favorite
37 Items, 2 Pages 1 2 |< << Go >> >|
"silversasoriza
NewsGroup User
how to display 1 row in textbox6/24/2006 2:09:22 AM

0

hi, i wanted to check whether the transactionID is correct or not from the database(access). if it is correct, then i would like to display the data in the correct row to a text file. so far, i can validate succesfully. However, im having trouble to get the whole row and display it.

  
Imports System.Data.OleDb

Imports homepage.configuration1

Public Class orderTracking

Inherits System.Web.UI.Page



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here


End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

Dim config1 As New homepage.configuration1

Dim strcon As String = config1.get_connection()

Dim con As OleDbConnection

Dim cmd As New OleDbCommand

Dim i As Integer

Dim reader As OleDbDataReader

'create a new connection


con = New OleDbConnection(strcon)

'create sql statement


cmd.CommandText = "SELECT count(*) from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"


cmd.Connection = con

con.Open()

i = cmd.ExecuteScalar()

reader = cmd.ExecuteReader()

If i <= 0 Then

lbError.Text = "No match found"

Else

While reader.Read()

txtBoxShipMethod.Text = reader("shippingCost").ToString

'lbCorrect.Text = "Found"


End While

End If

End Sub

End Class

 
 thx..
"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 7:20:47 AM

0

Hi
Welcome to ASP.Net forum!

You didnt wrote what problem you were getting in displaying the row. The method/syntax you were using is correct. If you want to get all the fields, just append the values

txtBoxShipMethod.Text = reader("shippingCost").ToString & reader("field1").ToString & ....

Thanks

Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 9:33:14 AM

0

 Hi, this is e error that i get...

Server Error in '/homepage' Application.
--------------------------------------------------------------------------------

shippingCost 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IndexOutOfRangeException: shippingCost

Source Error: 


Line 75:         Else
Line 76:             While reader.Read()
Line 77:                 txtBoxShipMethod.Text = reader("shippingCost").ToString
Line 78:                 'lbCorrect.Text = "Found"
Line 79:             End While
 

Source File: C:\Inetpub\wwwroot\homepage\orderTracking.aspx.vb    Line: 77 

Stack Trace: 


[IndexOutOfRangeException: shippingCost]
   System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)
   System.Data.OleDb.OleDbDataReader.GetOrdinal(String name)
   System.Data.OleDb.OleDbDataReader.get_Item(String name)
   homepage.orderTracking.btnSearch_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\homepage\orderTracking.aspx.vb:77
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

 

can i write sth like this to the textbox

txtBoxShipMethod.Text = reader("shippingCost").ToString

txtBoxDateArrive.Text = reader("dateArrived").ToString

 

thx =)

 
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 10:13:24 AM

0

You should correctify your query
You should do a batch query[separated by ;]In first query you should get the count and in the second query you should get the data.
Then execute the command you should get the two results.
First for count  second for your data
You also have to use NextResult
Search for the rest in google

Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 10:19:13 AM

0

Hi
Make sure shippingCost is an valid column name of the query you made to database.

Thanks


Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 10:25:36 AM

0

His problem is not column name as he is selecticg  Count(*) in the result set

Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 10:56:49 AM

0

i try to change it like this:

cmd.CommandText = "SELECT count(*); shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"

then it gives me this error

Server Error in '/homepage' Application.
--------------------------------------------------------------------------------

Characters found after end of SQL statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Characters found after end of SQL statement.

Source Error:


Line 68:         cmd.Connection = con
Line 69:         con.Open()
Line 70:         i = cmd.ExecuteScalar()
Line 71:         reader = cmd.ExecuteReader()
Line 72:


Source File: C:\Inetpub\wwwroot\homepage\orderTracking.aspx.vb    Line: 70

Stack Trace:


[OleDbException (0x80040e14): Characters found after end of SQL statement.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   System.Data.OleDb.OleDbCommand.ExecuteScalar()
   homepage.orderTracking.btnSearch_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\homepage\orderTracking.aspx.vb:70
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

 

** im using access as the database, can we use ";" with access??

thx

 

 
"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 11:10:05 AM

0

Hi
Still there is an error in your sql select statement. You have an extra character after the count(*). try removing it.

cmd.CommandText =
"SELECT count(*), shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"

Thanks

Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 11:53:38 AM

0

No this should Be like
cmd.CommandText =
"SELECT count(*) from shipment where trackingNo ='" & txtBoxOrderNo.Text & "' ;SELECT shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'

Then you should See how to use Datareader.NextResult

It will solve
check this link http://www.syncfusion.com/FAQ/aspnet/WEB_c8c.aspx?print=55

Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 12:48:56 PM

0

 
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim config1 As New homepage.configuration1
        Dim strcon As String = config1.get_connection()
        Dim con As OleDbConnection
        Dim cmd As New OleDbCommand
        Dim i As Integer
        Dim reader As OleDbDataReader

        'create a new connection

        con = New OleDbConnection(strcon)

        'create sql statement
        cmd.CommandText = "SELECT count(*) from shipment where trackingNo ='" & txtBoxOrderNo.Text & "' ;SELECT shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"

        cmd.Connection = con
        con.Open()
        i = CInt(cmd.ExecuteScalar())
        reader = cmd.ExecuteReader()

        If i <= 0 Then
            lbError.Text = "No match found"
        Else
            reader.NextResult()
            While reader.Read()
                txtBoxShipMethod.Text = reader("shippingCost").ToString
                'lbCorrect.Text = "Found"

            End While
        End If
    End Sub
 
i already change the code but now i got this error
Characters found after end of SQL statement. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.OleDb.OleDbException: Characters found after end of SQL statement.

Source Error: 


Line 69:         cmd.Connection = con
Line 70:         con.Open()
Line 71:         i = CInt(cmd.ExecuteScalar())
Line 72:         reader = cmd.ExecuteReader()
Line 73: 
 
Does NextReader() return the value of the next row?? 
 
 
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 12:52:40 PM

0

does it make any different if im using asp.net 1.1??

really2 thx

"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 2:44:42 PM

0

kamii47:
No this should Be like
cmd.CommandText =
"SELECT count(*) from shipment where trackingNo ='" & txtBoxOrderNo.Text & "' ;SELECT shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'

Then you should See how to use Datareader.NextResult


I dunno why it should be like that. 2 select statements to the command? What data do the command hold after the execution of the statements?? Also see, in your select statement, some of the text was commented mistakenly due to single quotes.

It doesn't make any difference with 1.1 and 2.0

Change your statement like this, and it should work. I guess you have not looked my previous post.
cmd.CommandText = "SELECT count(*), shippingCost from shipment where trackingNo = '" & txtBoxOrderNo.Text & "'"

Thanks




Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 6:09:29 PM

0

Mr E_screw Have you ever use NextResult ()
If not then Please see some documentation or see this Link
http://www.syncfusion.com/FAQ/aspnet/WEB_c8c.aspx#q377q

What the person is asking is only going to be solved "properly" by this way
Otherwise there are lot of ways


Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/24/2006 11:21:01 PM

0

i try to use this line n i got this error

cmd.CommandText = "SELECT count(*), shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"

Server Error in '/homepage' Application.

You tried to execute a query that does not include the specified expression 'shippingCost' as part of an aggregate function.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: You tried to execute a query that does not include the specified expression 'shippingCost' as part of an aggregate function.

Source Error:

Line 69:         cmd.Connection = con
Line 70:         con.Open()
Line 71:         i = CInt(cmd.ExecuteScalar())
Line 72:         reader = cmd.ExecuteReader()
Line 73: 

 then i also try using this line n i also got an error

cmd.CommandText = "SELECT count(*) from shipment where trackingNo ='" & txtBoxOrderNo.Text & "' ;SELECT shippingCost from shipment where trackingNo ='" & txtBoxOrderNo.Text & "'"

 

Server Error in '/homepage' Application.

Characters found after end of SQL statement.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Characters found after end of SQL statement.

Source Error:

Line 69:         cmd.Connection = con
Line 70:         con.Open()
Line 71:         i = CInt(cmd.ExecuteScalar())
Line 72:         reader = cmd.ExecuteReader()
Line 73: 

 

im really confuse now...

"tmorton" <>
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 12:26:11 AM

0

silversasoriza:
hi, i wanted to check whether the transactionID is correct or not from the database(access). if it is correct, then i would like to display the data in the correct row to a text file. so far, i can validate succesfully. However, im having trouble to get the whole row and display it.

Kamii47 is suggesting that you batch commands; this may or may not be possible depending on your database.  With SQL Server it is possible, with Access it is not.  Since you are using an OleDbCommand I suspect you are not using SQL Server.

Will the COUNT(*) ever return anything other than a 0 or 1?  That is, would there only be 1 record per trackingNo, or multiple records?

Since you are trying to place the result in a single textbox, I am going to assume there would only be 1 record per tracking No.  In that case, I would suggest code like this (note that I used a parameter; never concatenate UI-supplied data to a SQL string to be execute, this is insecure and opens up your application to SQL injection attacks):
  
Imports System.Data.OleDb

Imports homepage.configuration1

Public Class orderTracking

Inherits System.Web.UI.Page



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here


End Sub

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click

Dim config1 As New homepage.configuration1

Dim strcon As String = config1.get_connection()

Dim con As OleDbConnection

Dim cmd As New OleDbCommand

Dim shippingCost As String

'create a new connection


con = New OleDbConnection(strcon)

'create sql statement


cmd.CommandText = "SELECT shippingCost from shipment where trackingNo = ?"
cmd.Parameters.Add("trackingNo", OleDbType.VarChar, 50).Value = txtBoxOrderNo.Text
cmd.Connection = con con.Open() shippingCost = cmd.ExecuteScalar() If IsDbNull(shippingCost) Then lbError.Text = "
No match found" Else txtBoxShipMethod.Text = shippingCost 'lbCorrect.Text = "Found" End If End Sub End Class


Terri Morton
Program Manager, Telligent

Wissen ist Macht
How to ask a question
"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 4:00:50 AM

0

Yes, as Morton said, if there is a record for the corresponding trackingNo, then there is no need to check if records exists or not, lest it would be a null value.

I am not sure or used batch commands in code, as i always put my queries in a stored procedure.
Again, its always recommended to have parameters, as morton said!

Thanks


Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 8:48:37 AM

0

Well Nice silversasoriza.
As he is required a single column from resultset then It is
the best solution

Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"silversasoriza
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 9:05:53 AM

0

Hi, thx a lot.. it works...

one last question... i have more than one record per tracking no. i already change the code to:

cmd.CommandText = "SELECT shippingCost, shippingAddress, dateArrived from shipment where trackingNo = '" & txtBoxOrderNo.Text & "'"

I try it, and it shows the same value (shippingCost value)in all the 3 textbox.
If i have more than 1 record that means i cannot use the ExecuteScalar right??
then i try to use ExecuteReader but it didnt work as well. please teach me how to 
take 3 record...
thx again =)
 
"kamii47" <>
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 9:15:59 AM

0

Then You have to use executereader as executescalar will just return first column of the first row in the result set
You should populate your resultset in areader After using it check reader.Hasrow property which identify that your reader has rows or not.(its will return boolean true or false)
After it you can use
textbox1.text= reader["Columname1"].tostring()
textbox2.text= reader["Columname2"].tostring()
textbox3.text= reader["Columname3"].tostring()
e.t.c
For detail just google it
Hope it helps

Kamran Shahid (MCP,MCAD,MCSD.NET)
Sr. Software Engineer
Netprosys Inc.
www.netprosys.com
"e_screw" <>
NewsGroup User
Re: how to display 1 row in textbox6/25/2006 10:39:16 AM

0

kamii47:
Then You have to use executereader as executescalar will just return first column of the first row in the result set
You should populate your resultset in areader After using it check reader.Hasrow property which identify that your reader has rows or not.(its will return boolean true or false)
After it you can use
textbox1.text= reader["Columname1"].tostring()
textbox2.text= reader["Columname2"].tostring()
textbox3.text= reader["Columname3"].tostring()


He is talking about more rows.. not columns :P. You are checking for HasRow and referencing 3 columns, where actually he is getting one column but 3 rows. If you were using any method, then return an array of the rows, or else fill your textboxes in the while (reader.Read()) { // ... }

Thanks


Its not so easy to do... So you are here!

Electronic Screw
Website||Blog||Dub@i.net
37 Items, 2 Pages 1 2 |< << Go >> >|


Free Download:













response.write problems

where is my toolbox

access database class

reset controls

reference virtual directory

creating a data access layer and creating a business logic layer videos?

no rows in a dataset problem.

help on working with dal and bll classes

removing duplicate values from arraylist

how to retrieve output value from sql?

a basic questions about a string variable?

starting a process on server

broken images?

cs / vb files in seperate folder? question

&amp; instead of &

iis and asp .net

formview postbacks

replace broken image icon in gridview

iis not looking for classes in app_code by default...please help!

how can i tell vs.net 2005 to ignore some directories when i hit compilation?

what exactly means by executiontimeout

need help starting a c# asp.net project.

learning asp.net

conecting database to dataset created dynamically

sql need help with custom error

post headers..

server time || client time

default namespaces

regex to return content between two tags (ignoring inner tags)

button click event

user control a needs to access a user control b property - how?

connection pooling

cant create or open web applications

how to grab email id from mailbox

end of statement expected

comexception - system.runtimetype.forwardcalltoinvokemember???

problem when returning from a popup calendar

object creation

v1 and v1.1 - how to choose v1.1?

remoting

session variables

1.1 vs 2.0?

asp help

smartnavigation

problem with verbatim string

using web user controls as variables/objects in classes.

variables in one line

need help

masterpage with a menu control

database connectivity in c# and asp.net

   
  Privacy | Contact Us
All Times Are GMT