Cast from type 'ListItem' to type 'String' is not valid

Hi 

I am getting this error message when I try to view the sql of my insert command in the Oldbcommand1.commandtext statement. can somebody help me.
The insert statement is as follows:
(Most of the seesions are strings and the others come from a list item value (listitem.selecteditem.value)

OleDbCommand1.CommandText = "insert into wlc_mvts values ('" & trs & "','" & Session("payment_mode") & "','" & Session("freight") _
& "','" & Session("red_clause") & "','" & Session("revocable") & "','" & Session("stand_by") & "','" & Session("transport") & "','" & Session("maot_code") _
& "','" & Session("expiry_cntry") & "','" & Session("currency") & "','" & Session("transship") & "','" & Session("confirmation") & "','" & Session("transferrable") _
& "','" & Session("partial_ship") & "','" & Session("cust_id") & "','" & brch_code & "','" & brch_ref & "','" & Session("app_name") & "','" & Session("app_add1") _
& "','" & Session("app_add1") & "','" & Session("app_add2") & "','" & Session("app_add2") & "','" & Session("app_add3") & "','" & Session("acc_name") & "','" _
& Session("acc_add1") & "','" & Session("acc_add2") & "','" & Session("acc_add3") & "','" & Session("acc_add4") & "', to_date('" & FormatDateTime(Date.Today.Date, DateFormat.ShortDate) _
& "','dd/mm/yyyy'),'" & Session("amount") & "','" & Session("inc_perc") & "','" & Session("dec_perc") & "','" & Session("revolving") & "','" & Session("rev_times") _
& "','" & Session("cumul") & "','" & Session("cumul_amnt") & "', to_date('" & Session("expiry_lc_date") & "','dd/mm/yyyy'),'" & Session("expiry_place") & "','" & Session("adv_perc") & "','" _
& "','" & Session("adv_paymnt") & "','" & Session("sight_perc") & "','" & Session("sight_paymnt") & "', to_date('" & Session("sight_date") & "','dd/mm/yyyy'),'" _
& Session("sight_categ") & "','" & Session("sight_categ_nb") & "','" & Session("sight_pcev") & "','" & Session("time1_perc") & "','" & Session("time1_paymnt") _
& "', to_date('" & Session("time1_date") & "','dd/mm/yyyy'),'" & Session("time1_categ") & "','" & Session("time1_categ_nb") & "','" & Session("time1_pcev") & "','" _
& Session("time2_perc") & "','" & Session("time2_paymnt") & "', to_date('" & Session("time2_date") & "','dd/mm/yyyy'),'" & Session("time2_categ") & "','" _
& Session("time2_categ_nb") & "','" & Session("time2_pcev") & "','" & Session("time3_perc") & "','" & Session("time3_paymnt") & "', to_date('" _
& Session("time3_date") & "','dd/mm/yyyy'),'" & Session("time3_categ") & "','" & Session("time3_categ_nb") & "','" & Session("time3_pcev") & "','" _
& Session("time4_perc") & "','" & Session("time4_paymnt") & "', to_date('" & Session("time4_date") & "','dd/mm/yyyy'),'" & Session("time4_categ") & "','" _
& Session("time4_categ_nb") & "','" & Session("time4_pcev") & "','" & Session("time5_perc") & "','" & Session("time5_paymnt") & "', to_date('" _
& Session("time5_date") & "','dd/mm/yyyy'),'" & Session("time5_categ") & "','" & Session("time5_categ_nb") & "','" & Session("time5_pcev") & "','" _
& Session("time6_perc") & "','" & Session("time6_paymnt") & "', to_date('" & Session("time6_date") & "','dd/mm/yyyy') ,'" & Session("time6_categ") _
& "','" & Session("time6_categ_nb") & "','" & Session("time6_pcev") & "','" & Session("cert_perc") & "','" & Session("cert_paymnt") & Session("shipped_from") _
& "','" & Session("shipped_to") & "','" & Session("ben_accnt") & "','" & Session("ben_name") & "','" & Session("ben_adr1") & "','" & Session("ben_adr2") _
& Session("ben_adr3") & "','" & Session("ben_tlx") & Session("ben_fax") & "','" & Session("insurer_name") & "','" & Session("policy_ref") & "','" & Session("insured_curr") _
& "','" & Session("insured_amnt") & "','" & advising_swift.Text & "','" & advising_telex.Text & "','" & advising_name.Text & "','" & advising_adr1.Text & "','" _
& advising_adr2.Text & "','" & advising_adr3.Text & "', to_date('" & Session("contract_date") & "','dd/mm/yyyy'), to_date('" & Session("expiry_date") & "','dd/mm/yyyy'))"
0
michel_23
8/8/2003 9:01:40 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

15 Replies
766 Views

Similar Articles

[PageSpeed] 11

if you surround your code in 
 
tags we might have an idea of whats happening
:)
davey
0
daveym
8/8/2003 11:44:32 AM
I added the code tags.


Starting with ASP.NET 2.0? Look at:
Programming Microsoft Web Forms
My Blog
0
douglas
8/8/2003 11:58:53 AM
2 potential causes:

1) Your OleDbCommand object hates you for not building the string much more efficiently using the StringBuilder class, and then passing it in; or
2) Your OleDBCommand object hates you for not using a parameterized query.
Either way, it doesn't pay to make your OldDBCommand objects angry; they tend to hold a grudge.
Honestly, this is a mess. You need to clean it up...
-pjm

I never gave a damn about the meterman until I was the man who had to read the meter.
0
pjmcb
8/8/2003 12:22:28 PM
so what's happening ?

what's the problem...
0
michel_23
8/8/2003 12:37:19 PM
I agree...this is a mess, but what about the subject of your question:

Cast from type 'ListItem' to type 'String' is not valid
I always use CType(Session("var1"), string) when I retrieve something from a session variable.
Maybe one of the sessions variables is from a listbox?? and can't be changed to a string type??
That's my 2 cents...
Jerry
0
JerryK
8/8/2003 1:25:40 PM
I used Session("variable")= cstr(item control)  to convert the session variables into string when created.

By the way, I know about the mess but I am obliged to do this since the fields I am inserting into the table come from different web pages and contain at least 250 fields.
If there's another way than using session variables, I will be ready to adopt it.
I tried to use the multipage control but it prooved ineffcient since the fields in a certain page cannot be controled from the other pages, plus you have to write html code in order to create the controls. I have also tried to use panels but it prooved cumbersome to put all the panels on top of each others.
0
michel_23
8/8/2003 1:42:38 PM
If I had to guess, somewhere on one of the other pages where you are storing values into session varialbes, you accidently store the listitem, instead of the listitem value. But it's hard to tell without actually seeing the code...
-pjm

I never gave a damn about the meterman until I was the man who had to read the meter.
0
pjmcb
8/8/2003 2:13:29 PM
I don't think it matters how you store the session variables 'I used Session("variable")= cstr(item control) '  I think it matters how you retrieve them...And I agree with pjm that 'you accidently store the listitem, instead of the listitem value. '...

Why not create a table in a dataset, store that in your session and retieve the fields...When you're done, you just delete the one session variable (the dataset) instead of the 250+ you spoke about...
Jerry
0
JerryK
8/8/2003 2:23:27 PM
I will look to see if I forgot to put the listitem's value.

About the dataset, this is a good idea; I didn't know that we can store a dataset as a session variable I thought that only small string are used in sessions. I will try to do it.
By the way, can you give me any related docs to storing values in datasets?
Thank you for ur help.
0
michel_23
8/9/2003 6:45:32 AM
I believe you can store any kind of variable in session, as long as it's 'serializable'...I created my own collection-type variable and can store it in session because it's serializable - datasets, by the way, are serializable...

You should have no problem storing your data...
JK
0
JerryK
8/10/2003 11:42:33 PM
Can u help me and tell me how to create a dataset with a certain structure, the same as a table structure, and store data in it.

0
michel_23
8/11/2003 1:30:07 PM
Here's a URL for you to read and use for example...

http://www.pinnaclepublishing.com/ne/nemag.nsf/0/3571AD425A36383A85256A230072E8FD
There are plenty of others - I go to Google, and search using
"ASP.NET" Datasets "ADO.NET"
You might want to look at www.learnvisualstudio.net
Some of the videos are free, some cost $15 for 3 months access...You could download everything they have...
Jerry
0
JerryK
8/11/2003 5:18:51 PM
By the way I checked if all my sessions related to list items return their values and it showed that I am returning the values of the list items correctly.

So it's not a problem of returning a value to a session.
What could be the other possibilities of getting the error mentioned in my previous questions?
Thank You
0
michel_23
8/12/2003 10:03:03 AM
What I would do next is get a copy of the table design you are trying to update.  Then, 'DIM' variables inside your code-behind that correspond to your table definition.  Move all of the session variables into your newly DIMmed variables, then try the INSERT...


Jerry
0
JerryK
8/12/2003 12:46:09 PM
I made what u suggested and things worked fine. Thank you for ur help.

I still didn't transform my session variables into a dataset, I will try to do it but most importantly that I can now save my session variables into the database table
0
michel_23
8/13/2003 9:59:54 AM
Reply:

Similar Artilces:

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...

Cast from type 'Field' to type 'String' is not valid
I am getting the error msg on this code...Response.Write(objRSCount("iCount") & " records for " & frmDispOption & " '" & frmText & "'. They are listed below:")I have tried converting the frmDispOption and frmText variables to strings using CStr after getting the values from the DB but still get the same msg.  Can someone please help me out, thanks.David. What is "objRSCount"? ie what type is it? You also need to make sure that objRSCount("iCount") is string.ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Blog||Dub@i.net Hi, i f...

Cast from type 'Byte()' to type 'String' is not valid.
Hello - I need to use the id from one query to throw into another query. Thing is the id in the first database is in the format: 0x00000000000227F1 but when it shows in a data grid. it just shows: Byte[] Array I need to get the value of Byte[] Array as a string in the format: 0x00000000000227F1 When I query it in query analyzer, it shows as: 0x00000000000227F1 but, like I say, in my data grid , it just shows as Byte[] Array So when I try to use it in a query I get the error: Cast from type 'Byte()' to type 'String' is not valid. Any ideas? Thanks ...

Cast from type 'DBNull' to type 'String' is not valid.
Hi, I have a page with several textboxes...it's a "change your account" page. One of the parameters is presented as a label instead since it is not changed ON THIS PAGE. It needs to be NULL when the account is created and entered later. But when the page loads, I get the above error. The account row is loaded from a business object LoadFromId(). How can I load the page even though this label data is NULL to start with? relevent code below. <asp:Label ID="lblDDAccount" Runat="server"></asp:Label>------If currentUser.DDAccount = "" Then       &...

Cast from type 'HttpCookie' to type 'String' is not valid
Hi. I am currently storing data in a cookie (an ID from a database) which i then want to retrieve and use to generate a file name for an uploaded file later on, which will be stored on disk. I get the error "Cast from type 'HttpCookie' to type 'String' is not valid". I assume i need to find a way to convert the data to string? A little help pleeeze, code examples too ;-) Sounds like you may have missed specifing the value property. If you're trying to get the value into a string variable, for instance, something like this: (VB) Dim var As String var = R...

Cast from type 'DBNull' to type 'String' is not valid.
Ok, that is the error... "Cast from type 'DBNull' to type 'String' is not valid. " I am filling a DataSet from the db and some fields are empty. Reading from it and placing the info into a label. Code below.... Sub getProductInfo() Dim DSprod2 As New DataSet() Dim MyCommand As OleDbDataAdapter sql = "Select * from tblProducts Where fldNum = " & intfldNum MyCommand = New OleDbDataAdapter(sql, conn) MyCommand.Fill(DSprod2, "tblProducts") lblProd.Text = DSprod2.Tables("...

Cast from type 'DBNull' to type 'String' is not valid.
How would I check to make sure my SQL db is not pulling a null value? I'm using the following code and I get the 'Cast from type 'DBNull' to type 'String' is not valid.' error. If (dtrUserDetails("D_Address2") Is System.DBNull.Value) Then _Address2 = "" Else _Address2 = dtrUserDetails("D_Address2") End If Any help would be much appreciated. Change your line to _Address2=dtrUserDetails("D_Address2") & "" The empty string in the end will convert the filed to a string ...

Cast from type 'DBNull' to type 'String' is not valid
Hi,  I have an old website and old database (SQL 2000).  I add new column "ImageURL' to database, so all data (several thousand items) are "NULL" (actually is dbNull) under this column.  In searchResult.aspx page, inside the datagrid, I add a colummn call "Image" <code> <asp:datagrid id="dgSearchResult" runat="server"><Columns><asp:TemplateColumn HeaderText="Image" ItemStyle-Width="55px" ItemStyle-HorizontalAlign=Center> <ItemTemplate> <asp:Image ID=ThumbImage Wi...

Cast from type 'DBNull' to type 'String' is not valid
I REALLY need some help, so here goes. The following function does work as long as the "mail" field in the database isn't NULL. As you can see I have tried a couple of ways to check for a NULL value but none of them seem to work. What's supposed to happen is the function checks to see whether or not a user has an email address in the database. If so, then the email address gets returned, if no email address then I need something back from the function so I can go about another way to get the info to the user. Public Function GetReqByEmail(ByVal reqby As String) As String...

Cast from type 'DBNull' to type 'String' is not valid.
On the viewproduct page if any of the db fields referenced in the SP are empty you get the above error, the error originates in the productsDB.vb file as follows myProductDetails.ModelNumber = CStr(parameterModelNumber.Value) myProductDetails.ModelName = CStr(parameterModelName.Value) myProductDetails.ProductImage = CStr(parameterProductImage.Value).Trim() myProductDetails.UnitCost = CType(parameterUnitCost.Value, Decimal) myProductDetails.Description = CStr(parameterDescription.Value).Trim() OK I can make ...

Cast from type 'DBNull' to type 'String' is not valid
 Hi all,Sorry to be posting here on what is probably a common enough error but I am at my wits end with this one. Quite simply I call an Update stored procedure in my code, passing in a number of paramaters. However, when I try to run the code, the following exception is thrown:Cast from type 'DBNull' to type 'String' is not validI'm really not sure what the problem is here. I have tried hardcoding values for the string values with no success also, as well as using the IsNothing function, but no joy there eitherI would really appreciate someones help as I spent 2 hou...

Cast from type 'DBNull' to type 'String' is not valid. #2
i have an login page which use e-mail address and password to login , once the system comfirm this is valid login it get customer details and in my login page i have the following code Dim loginsystem As onlineshop.Customers = New onlineshop.Customers() Dim customerId As String = loginsystem.customer_login(login.email_address, login.password) If customerId <> "" Then Dim customerDetails As onlineshop.customer_Detail = loginsystem.Get_Customer_Details(customerid) and at the onlineshop.customer_detail function i have the following ...

Cast from type 'DBNull' to type 'String' is not valid. #3
Hi Everyone, I am trying this very simple select statement and storing my information into arrays but i am receiving the above error whenever the field has a NULL as value.I have looked at other similar post in this forum and know that i need to check if the string is empty but somehow i do not know the exact syntax to do this check.  Please help. Dim conAct As SqlConnectionDim cmdSelectAct As SqlCommandDim dtrAct As SqlDataReaderconAct = New SqlConnection("etc etc")conAct.Open()cmdSelectAct = New SqlCommand("Select EMPLID,USERID etc etc  from TABLE where STATUS='I'", conAct)...

Cast from type 'DBNull' to type 'String' is not valid. Error
Hi, Can anyone help me with an error I am receiving "Cast from type 'DBNull' to type 'String' is not valid."  I am creating an aspx page in VB.NET, please find attached code causing error.objCmd = New SqlCommand("USP_DisplayEmbarkDetails", objConn)  objCmd.CommandType = CommandType.StoredProcedure  objCmd.Parameters.Add("@BranchID", lblGetBranchID.Text)  objConn.Open()  objRdr = objCmd.ExecuteReader()    While objRdr.Read     lblBranchName.Text=objRdr("BranchName")    lblBranchID.Text=objRd...

Web resources about - Cast from type 'ListItem' to type 'String' is not valid - asp.net.web-forms

Resources last updated: 2/11/2016 12:10:47 PM