Invalid use of '.', '!', or '()'. in query expression 'CType(e.Item.Cells(1).Controls(0), TextBox).Text'.

Hi ppl, hope u can solve my prob, i getting this error:

<Code>

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

If Not Page.IsPostBack Then

BindData()

End If

End Sub

Sub BindData()

'1. Create a connection

Const strConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=c:\inetpub\wwwroot\IT2691\speedy.mdb;"

Dim objConn As New OleDbConnection(strConnStr)

objConn.Open()

'2. Create a command object for the query

Const strSQL As String = "SELECT * FROM Products"

Dim objCmd As New OleDbCommand(strSQL, objConn)

'3. Create/Populate the DataReader

Dim objDR As OleDbDataReader

objDR = objCmd.ExecuteReader()

dgUpdateGrid.DataSource = objDR

dgUpdateGrid.DataBind()

End Sub

Sub dgUpdateGrid_Edit(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

dgUpdateGrid.EditItemIndex = e.Item.ItemIndex

BindData()

End Sub

Sub dgUpdateGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

dgUpdateGrid.EditItemIndex = -1

BindData()

End Sub

Sub dgUpdateGrid_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)

'Read in the values of the updated row

Dim iProductID As Integer = e.Item.Cells(1).Text

Dim strName As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Dim strType As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text

Dim strDesc As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text

Dim dblPrice As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text

Dim strImage As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text

Dim strStockQty As String = CType(e.Item.Cells(7).Controls(0), TextBox).Text

Dim strRemarks As String = CType(e.Item.Cells(8).Controls(0), TextBox).Text

'Construct the SQL statement using Parameters

Dim strSQL As String = _

"UPDATE Products SET product_name = CType(e.Item.Cells(1).Controls(0), TextBox).Text, product_type = CType(e.Item.Cells(2).Controls(0), TextBox).Text, product_desc = CType(e.Item.Cells(3).Controls(0), TextBox).Text, unit_price = CType(e.Item.Cells(4).Controls(0), TextBox).Text, product_image = CType(e.Item.Cells(5).Controls(0), TextBox).Text, stock_qty = CType(e.Item.Cells(6).Controls(0), TextBox).Text, remarks = CType(e.Item.Cells(7).Controls(0), TextBox).Text "

Const strConnString As String = _

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\inetpub\wwwroot\IT2691\speedy.mdb;"

Dim objConn As New OleDbConnection(strConnString)

objConn.Open()

Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, objConn)

myCommand.CommandType = CommandType.Text

myCommand.ExecuteNonQuery() 'Execute the UPDATE query

objConn.Close() 'Close the connection

'Finally, set the EditItemIndex to -1 and rebind the DataGrid

dgUpdateGrid.EditItemIndex = -1

BindData()

</Code>

0
NgSG
8/11/2005 12:44:17 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

13 Replies
1543 Views

Similar Articles

[PageSpeed] 2

Hi, you didn't use the string concatenation for the strSQL. It would be something like

"UPDATE Products SET product_name ='" + strName + "', product_type ='" + strType + "',  ..............



Make sure you have reference the right correct cell. Hope it helps...

Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/11/2005 2:04:21 PM
Hi alvinz_c, it can work.. bt when i modify again, it end up wif this error of    'Input string was not in a correct format'

the above below is wat i modified

<code>

Dim strSQL As String = "UPDATE Products SET product_name = '" + strName + "', product_type = '" + strType + "', product_desc = '" + strDesc + "', unit_price = '" + dblPrice + "', product_image = '" + strImage + "', stock_qty = '" + strStockQty + "', remarks = '" + strRemarks + "' where product_id = '" + iProductID + "' "

</code>

any idea wat is wrong wif the format? help is appreciated

0
NgSG
8/11/2005 4:32:02 PM
hmm.. i juz tink isit modify to this " where product_id = 'iProductID'   " den it can solve, bt nw i gt "Data type mismatch in criteria expression", can somebody help me? 

btw, i set the product_id to be non-editable as it is my primary key.

den my ms access db for my Products is:

product_id         autonumber
product_name    text
product_type     text
product_desc     text
unit_price           currency
product_image   text
stock_qty          number
remarks             text


hope u all will help me :)
0
NgSG
8/11/2005 4:45:02 PM

Hi, your product_id, unit_price and stock_qty are numeric data types. Hence, in your query statement, do not prefix it with ' (single quote). For instance,

product_id = '" + iProductID + "' "

change it to

product_id =" + iProductID

Please do the same thing to the unit_price and stock_qty. Hope it works..


Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/12/2005 3:03:05 PM
Hi again, i have change the codes to the following below:

<code>

Dim strSQL As String = "UPDATE Products SET product_name = '" + strName + "', product_type = '" + strType + "', product_desc = '" + strDesc + "', unit_price = + dblPrice + , product_image = '" + strImage + "', stock_qty = + strStockQty + , remarks = '" + strRemarks + "' where product_id = iProductID "

</code>

nw i have this error: Syntax error (missing operator) in query expression '+ dblPrice +' .

sorry to trouble u and those ppl who read this post, can u all help me to solve this problem? cos i'm really a newbie in SQL as well...

ur help is appreciated.

0
NgSG
8/12/2005 3:19:31 PM

Try this

Dim strSQL As String = "UPDATE Products SET product_name = '" + strName + "', product_type = '" + strType + "', product_desc = '" + strDesc + "', unit_price = " + dblPrice + ", product_image = '" + strImage + "', stock_qty =" + strStockQty + ", remarks = '" + strRemarks + "' where product_id =" + iProductID

Hope it works...


Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/12/2005 4:42:15 PM

Hi, sorry to say ur code can't work. Input string was not in a correct format.

0
NgSG
8/12/2005 5:50:43 PM
Dim iProductID As Integer = e.Item.Cells(1).Text

You have to change it to String.... Hope it helps...

Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/12/2005 6:23:33 PM
Hi, after i changed to String for my iProductID, i get Syntax error in query expression '$1'.

The $1 is the price, which is dblPrice, is get frm the database.

Anybody noe y?
0
NgSG
8/13/2005 1:17:48 AM
You have to eliminate the '$' from the string dblPrice before passing it into the strSQL. Hope it helps..
Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/13/2005 3:23:36 AM
Hi, how do i remove the $, cos in my database, the unit_price is set to currency which will auto giv it the $. Do i changed it to text or number den it can work?
0
NgSG
8/13/2005 3:32:08 AM

Hi, you can change the datatype to the number.The alternative way is

dblPrice.Replace("$","");

Hope it helps...


Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog : http://alvinzc.blogspot.com
0
alvinz_c
8/13/2005 3:05:12 PM
Hi, i would like to try with dblPrice.Replace("$","")instead of changin the datatype, bt where should i put the codes?

thx
0
NgSG
8/13/2005 3:27:32 PM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

'b'..'a'
Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated ...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

'To', 'CC', & 'BCC'
Name: Dick Tracy Email: philipdottracyatoptusnetdotcomdotau Product: Thunderbird Summary: 'To', 'CC', & 'BCC' Comments: I have just started using Thunderbird and while I find it quite excellent- I suggest having a button to add addressees to 'BCC' as well. Currently each 'BCC' addressee has to be selected manually. I send e-mail to quite a number of people at a time and I do not wish to readily spread others addresses easily. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0....

EXEC sp_msforeachtable 'sp_spaceused ''?'''
What does the following SQL code mean?  EXEC sp_msforeachtable 'sp_spaceused ''?'''Johan TheunissenMCPD, MCSE, MCTS BizTalk 2006==============================Please mark the most helpful reply/replies as "Answer". JohanNL:sp_msforeachtable This is the name of the SP that resides in the master database.  This SP executes one or more commands for a table. JohanNL:sp_spaceused This is the command that you want to run for each of the tables residing in your current database.  As you might have understood so far, that this is again a...

HOw to use __doPostback('','')?????????
Hi i use the window.open() javascript function, then i want to use the __doPostback('','') javascript function to force the page post back , so that i can use the parameter pass from the child window in the page.ispostback event. but i try to use __doPostback('','') in my 1.1 .net framework, nothing happen????? how to use the __doPostback('','') or how to let the page have .postback event?SelfConfident is get from the Xperience You need to use the server-side function: Page.GetPostBackEventReference and tell it what control's event you want to fire. The __doPostBa...

Using '[' and ']' characters...
Has anyone come across the following problem when using PD7.5 on SQL Server 2000? PD7.5 does not generate the '[' and ']' characters for stored procedures. Example: CREATE PROC P_Test AS SELECT A AS [Column A] FROM A_Table Generated script: CREATE PROC P_Test AS SELECT A AS Column A FROM A_Table Thanks in advance, Aiden That's interesting. In 7.5, if I put [[Column A]] in the procedure definition, I get [Column A]. In 8.0 it works correctly. -- Michael F. Nicewarner [TeamSybase] mailto:psyclo@datamodel.org http://www.datamode...

Web resources about - Invalid use of '.', '!', or '()'. in query expression 'CType(e.Item.Cells(1).Controls(0), TextBox).Text'. - asp.net.presentation-controls

Resources last updated: 12/21/2015 10:36:19 AM