Property access must assign to the property or use its value

 Hi, I when I tried to build my solution in vs2003 I get the following error message.

"Property access must assign to the property or use its value."

The following is my code to help you better understand my situation.


Imports System.IO
Imports System.Data.Odbc
Public Class Upload
    Inherits System.Web.UI.Page

 Private Sub Submit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.Click
        Dim strFileExtension As String
        Dim StrFileType As String
        Dim intFileLen As Integer
        Dim objStream As Stream
        Dim strInsert As String
        Dim myConnection As OdbcConnection
        Dim cmdInsert As OdbcCommand


        If Not IsNothing(txtFileContents.PostedFile) Then
            'Determines File Type
            strFileExtension = Right(txtFileContents.PostedFile.FileName, 4)
            Select Case strFileExtension.ToLower
                Case ".doc"
                    StrFileType = "doc"
                Case ".ppt"
                    StrFileType = "ppt"
                Case ".htm"
                    StrFileType = "htm"
                Case ".html"
                    StrFileType = "html"
                Case ".txt"
                    StrFileType = "txt"
                Case Else
                    StrFileType = "jpg"
            End Select
            'Grab the content of uploaded file
            intFileLen = txtFileContents.PostedFile.ContentLength
            Dim arrFile(intFileLen) As Byte
            objStream = txtFileContents.PostedFile.InputStream
            objStream.Read(arrFile, 0, intFileLen)


            'Add UpLoaded file to a database
            myConnection = New OdbcConnection("Provider=MySQLProv; Data Source=Data;User Id=myID;Password=myPWD")
            strInsert = "INSERT into QUsers (docTitle,docContent,docDate,docType) values (?,?,?,?,?)"
            cmdInsert = new odbcCommand(strInsert,myConnection)
            
            cmdInsert.Parameters.Add("@docID",OdbcType.int,30)           
            cmdInsert.Parameters["@docID"].Values =""

            cmdInsert.Parameters.Add("@docDate", OdbcType.TimeStame,14)             
            cmdInsert.Parameters["@docDate"].Values = DateTime.Now.ToShortDateString()

            cmdInsert.Parameters.Add("@docTitle", OdbcType.Varchar,30  )
            cmdInsert.Parameters["@docTitle"].Values = txtFileTitle.Text       
            
            cmdInsert.Parameters.Add("@docType", OdbcType.Varchar,30)
            cmdInsert.Parameters["@docType"].Values =StrFileType

            cmdInsert.Parameters.Add("@docContent",OdbcType.Text)           
            cmdInsert.Parameters["@docContent"].Values =arrFile
            
            myConnection.Open()
            cmdInsert.ExecuteNonQuery()
            myConnection.Close()
        End If

    End Sub
End Class

0
ProgMaster
6/6/2007 11:18:31 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

12 Replies
1482 Views

Similar Articles

[PageSpeed] 51
Get it on Google Play
Get it on Apple App Store

change the square brackets [] to parenthesis () and change the Values property to a Value property.
there is also a typo on the OdbcType.Timestamp

 cmdInsert.Parameters.Add("@docID", OdbcType.int, 30)
 cmdInsert.Parameters("@docID").Value = ""
 
 cmdInsert.Parameters.Add("@docDate", OdbcType.Timestamp, 14) 'timestamp
 cmdInsert.Parameters("@docDate").Value = DateTime.Now.ToShortDateString()
 
Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/7/2007 1:23:56 AM

 Thanks alot that did the trick, but now it says "An OdbcParameter with ParameterName'@docID' is not contained by this OdbcParameterCollection". I don't know what that means, I've looked up the error message online but couldn't find anything helpful on it. I've been trying to make this little app work for weeks but I'm getting no where fast. Please help locate the problem cause I've gone through the code many times but I still don't see anything  wrong. Thank you again for your time.

0
ProgMaster
6/7/2007 2:41:05 AM

assuming that your db has the docID column set as an identity column, it will auto populate so you wont need to insert a value for it.

i would try commenting out these 2 lines

' cmdInsert.Parameters.Add("@docID", OdbcType.int, 30)
' cmdInsert.Parameters("@docID").Value = ""
 
Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/7/2007 2:47:31 AM

 The following is my db created in MySQL , docID was setup to increment automatically each time someone uploads a file to the database.

----------------------------------------------------------------------------------------------------------------------------------------    
 |  Field              |   Type              |   Null         |   Key           |  Default                              |   Extra                     |
----------------------------------------------------------------------------------------------------------------------------------------
 | docID              | int(11)             | NO            |   PRI            |  NULL                                | AUTO_INCREMENT   |
 |

 | docTitle          | varchar(30)      | NO           |                    |    NULL                              |                                 |
 |

 | docContent    |        text               | NO           |                   |    NULL                               |                                |
 |

 | docDate         | timestamp        | NO            |                    |    CURRENT_TIMESTAMP    |                                |
 |

 | docType        | varchar(15)       | NO          |                    |    NULL                               |                                |
----------------------------------------------------------------------------------------------------------------------------------------

 Please point out any problems that you see with this database. Thank you so much for your help.

 

0
ProgMaster
6/7/2007 3:03:44 AM

your insert statement only uses 4 parameters and correctly does not include the docID as the db will set that

    strInsert = "INSERT into QUsers (docTitle,docContent,docDate,docType) values (?,?,?,?,?)"

so you do not need to include the @docID parameter


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/7/2007 3:21:22 AM

 Thanks for all your help I'm still not able to upload anything to the database. It now says " Invalid Cast from System.String to System.Byte[] " Thanks for being patient with me, I'm very frustrated at the moment especially when I've been stuck at this spot in the program for over a week now.

0
ProgMaster
6/7/2007 3:40:13 AM

ProgMaster:
Invalid Cast from System.String to System.Byte[]
 

            cmdInsert.Parameters.Add("@docID",OdbcType.int,30)           
            cmdInsert.Parameters["@docID"].Values =""

            cmdInsert.Parameters.Add("@docDate", OdbcType.TimeStame,14)             
            cmdInsert.Parameters["@docDate"].Values = DateTime.Now.ToShortDateString()

            cmdInsert.Parameters.Add("@docTitle", OdbcType.Varchar,30  )
            cmdInsert.Parameters["@docTitle"].Values = txtFileTitle.Text       
            
            cmdInsert.Parameters.Add("@docType", OdbcType.Varchar,30)
            cmdInsert.Parameters["@docType"].Values =StrFileType

            cmdInsert.Parameters.Add("@docContent",OdbcType.Text)           
            cmdInsert.Parameters["@docType"].Values =arrFile 

check out the code which is marked as BOLD . i think there is some problem ... may be while doing copy and paste you are again giving value to "@docType" parameter in last line :-) .

hope this helps./.

Good Luck. 

 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
6/7/2007 5:43:19 AM

ProgMaster:
            
            cmdInsert.Parameters.Add("@docContent",OdbcType.Text)           
            cmdInsert.Parameters["@docType"].Values =arrFile


There is a typo, that you are trying to set the arrFile to the @docType parameter.

ProgMaster:
| docCOntent    | varchar(800)    | NO           |                   |    NULL                               |                                |


Your database structure tells that docContent is of varchar datatype, whereas you are passing in binary data. Change your datatype to hold binary data for the docContent field and the last lines of your code should read

cmdInsert.Parameters.Add("@docContent", OdbcType.Binary)
cmdInsert.Parameters("@docContent").Value = arrFile

Thanks


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
6/7/2007 6:07:02 AM

 Hi, I have fixed the little errors that you have pointed out and also changed the database so that the docContent field holds data of type text. I now have a new problem, I now get the exception "Invalid cast from System.String to System.Byte[]." Below are my current database and code to help you spot where the source of the error is. Please help me resolve this problem, I've been stuck with it for way too long. Thank you so much for your time.


----------------------------------------------------------------------------------------------------------------------------------------    
 |  Field              |   Type              |   Null         |   Key           |  Default                              |   Extra                     |
----------------------------------------------------------------------------------------------------------------------------------------
 | docID              | int(11)             | NO            |   PRI           |  NULL                                 | AUTO_INCREMENT   |
 |

 | docTitle          | varchar(30)      | NO           |                    |    NULL                               |                                 |
 |

 | docContent    |        text          | NO           |                    |    NULL                                |                                |
 |

 | docDate         | timestamp        | NO           |                    |    CURRENT_TIMESTAMP     |                                |
 |

 | docType        | varchar(15)       | NO          |                     |    NULL                               |                                |
----------------------------------------------------------------------------------------------------------------------------------------


Imports System.IO
Imports System.Data.Odbc
Public Class Upload
    Inherits System.Web.UI.Page

Private Sub Submit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.Click
        Dim strFileExtension As String
        Dim StrFileType As String
        Dim intFileLen As Integer
        Dim objStream As Stream
        Dim strInsert As String
        Dim myConnection As OdbcConnection
        Dim cmdInsert As OdbcCommand

        If Not IsNothing(txtFileContents.PostedFile) Then

            'Determines File Type
            strFileExtension = Right(txtFileContents.PostedFile.FileName, 4)
            Select Case strFileExtension.ToLower
                Case ".doc"
                    StrFileType = "doc"
                Case ".ppt"
                    StrFileType = "ppt"
                Case ".htm"
                    StrFileType = "htm"
                Case ".html"
                    StrFileType = "html"
                Case ".txt"
                    StrFileType = "txt"
                Case Else
                    StrFileType = "jpg"
            End Select
            'Grab the content of uploaded file
            intFileLen = txtFileContents.PostedFile.ContentLength
            Dim arrFile(intFileLen) As Byte
            objStream = txtFileContents.PostedFile.InputStream
            objStream.Read(arrFile, 0, intFileLen)

            'Add UpLoaded file to a database
            myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=ResumesDB;User=myID;Password=myPassWord;Option=3;")
            strInsert = "INSERT into ContentTbl (docDate,docTitle,docType,docContent)value (?,?,?,?)"
            cmdInsert = New OdbcCommand(strInsert, myConnection)
        
            cmdInsert.Parameters.Add("@docDate", OdbcType.Timestamp, 14)
            cmdInsert.Parameters("@docDate").Value = DateTime.Now.ToShortDateString()

            cmdInsert.Parameters.Add("@docTitle", OdbcType.VarChar, 30)
            cmdInsert.Parameters("@docTitle").Value = txtFileTitle.Text

            cmdInsert.Parameters.Add("@docType", OdbcType.VarChar, 30)
            cmdInsert.Parameters("@docType").Value = StrFileType

            cmdInsert.Parameters.Add("@docContent", OdbcType.Text)
            cmdInsert.Parameters("@docContent").Value = arrFile

            myConnection.Open()
            cmdInsert.ExecuteNonQuery()
            myConnection.Close()
            lblMessage.Text = "Complete!"

        End If
        txtFileTitle.Text = ""
    End Sub

0
ProgMaster
6/7/2007 7:14:39 AM

You want to store the content of the document in docContent field. With datatype set as "Text" for field docContent, you cannot store the file content (arrFile) is an array of bytes.

Change the datatype of docContent to "BLOB" or "MEDIUMBLOB" or "LONGBLOB" depending on the size you need and change your code as

            cmdInsert.Parameters.Add("@docContent", OdbcType.Binary)
            cmdInsert.Parameters("@docContent").Value = arrFile

Thanks


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
6/7/2007 7:36:58 AM

Thank you so much for taking the time to answer my questions. I really don't know what else to do as I am very green at this. I have changed the docContent column so that it holds data of  type MediumBlob, and changed the code in the program as you have suggested. However, the same error still persists and VS2003 had the line "cmdInsert.ExecuteNonQuery() " marked in red indicating that it is the cause of the problem. At this point I am not certain if that line is the problem. Could you please run my code on your machine to see if it works using the changes that you have suggested. I would really like to know what is going on. I am a novice and would really like to get the hang of this. Thank you again for your valuable time.

 ----------------------------------------------------------------------------------------------------------------------------------------    
 |  Field              |   Type              |   Null         |   Key           |  Default                              |   Extra                     |
----------------------------------------------------------------------------------------------------------------------------------------
 | docID              | int(11)             | NO           |   PRI            |  NULL                                 | AUTO_INCREMENT   |
 |

 | docTitle          | varchar(30)      | NO           |                    |    NULL                               |                                 |
 |

 | docContent    | MediumBlob     | NO           |                    |    NULL                               |                                 |
 |

 | docDate         | timestamp        | NO           |                    |    CURRENT_TIMESTAMP     |                                |
 |

 | docType        | varchar(15)       | NO           |                    |    NULL                               |                                |
----------------------------------------------------------------------------------------------------------------------------------------

0
ProgMaster
6/7/2007 8:38:35 AM

ProgMaster:
However, the same error still persists and VS2003 had the line "cmdInsert.ExecuteNonQuery() " marked in red indicating that it is the cause of the problem

ExecuteNonQuery returns (int), the number of rows affected by the executed sql statement. In your code, you have called it just as a void method, so is why the error.

            myConnection.Open()
            Dim i As Integer = cmdInsert.ExecuteNonQuery()
            myConnection.Close()
            lblMessage.Text = "Complete!"

Thanks


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
6/9/2007 2:30:31 PM
Reply:

Similar Artilces:

Property access must assign to the property or use its value.
I have a very basic function in my data access layer, which seems as though it is structured the same as my other functions, however it raises an error I've never seen, and I'm not sure what it means. The message reads "Property access must assign to the property or use its value."My code is as follows: Public Shared Function GetFirstPage(ByVal ParenGroupID As Int32) As SqlDataReaderDim myConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))Dim cmd As SqlCommand = New SqlCommand("MGMT_GetFrontPostPage", myConn)cmd.CommandType = CommandType.StoredPr...

BC30545: Property access must assign to the property or use its value.
Hi, I'm new to ASP.NET, and I've been going through the Webcasts that Bill Steel made - the 26 part series. Anyway, I'm on creating my first app, a calculator page, supposedly simple.  I came across the following error when testing the page, and I followed the video, verbatim, and still can't get my page to come up. BC30545: Property access must assign to the property or use its value.Here's the code in my Calc.aspx page: ========BEGIN CODE calc.aspx================ <% page language="VB" CodeFile="Calc.aspx.vb" Inherits="Calc_aspx" %> <html>  <head><ti...

Property access must assign to the property or use its value. #2
 Hi all.I am attempting to pass a parameter (called id) contained within the URL from one page to another using <% request.querystring("id") %>, however, when i do this i am presented with the following error message.'Property access must assign to the property or use its value.' The URL is as follows http://www.mywebsite.co.uk/spareparts/admin/edit-part.aspx?id=12 And i am using the following code to try and access and use this value <a href="change-part-type.aspx?id=<% request.querystring("id") %>"> LINK TO OT...

Error: Property access must assign to the property or use its value.
Hello, I am having a problem and I am not sure what I am doing wrong with my property: Private ReadOnly Property returnUsername() As String Get If Page.IsPostBack() = True Then returnUsername = ToString(usernametxt.Text)Return returnUsername Else returnUsername = ""Return returnUsername End If End Get End Property  I getting the error: Property Access must assign to the property or use its value.  I thought I was already doing that. Any help will be greatly appreciated. Thanks  I think you cannot use page.ispostback() from the property(i think...

Error: Property access must assign to the property or use its value.
 I am working on a project and I need to set the default values to load in the text boxes. When I insert the default values it displays the error message Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 ...

HELP! BC30545: Property access must assign to the property or use its value
Hi,   Im using a 4guysfromrolla sample to bind sqldatasource results to a label.  However Im getting the above error.  Here is my code:-----------------------------------------------------------------------------------------------------------------------------------Imports System.Data Partial Class datareaderInherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.LoadDim dv As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView) Dim rndCoinFlip As New RandomRandomProductNames.Text = St...

what does "Property access must assign to the property or use its value" means?
Hi, I am using .net 1.x here, trying to pre-select a binded checkbox list, but it complains:Property access must assign to the property or use its value I'm not sure what I did wrong with my code, would anyone please take a look at it for me please?[code asp.net]Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         'load the checkboxlist with value from myClass        cblst.DataSource = myClass.getCheckBoxList()        cblst.DataB...

Error message "Property access must assign to the property ir its value." ???im just learning .. heeeelp
When i try to "Build my web page" i get this error message from my coding of a Button click to label.. Im doing it just like to tutorial and it does NOT work.. Is my VB Web developer Express not fully activated for creating events? Help me. Ive spent so much time downloading and watching movies and im stuck 30 seconds into my first page.. Please show your code where the error is occurring.Thanks, EdMicrosoft MVP - ASP/ASP.NET Partial Class _Default Inherits System.Web.UI.PageProtected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles But...

getting a property value when expression is used on property
Hi everyone, I'm using PB10.2.0.8011 on Windows XP. I hate asking fundamental questions for which I know the answer lies in a manual, but I am having a rough time finding the answer to my question. I initially created a computed column with expression: describe("day1.x"), which refers to a dw object's property which in itself has an expression defining the value. The result is as expected a value of the form value~texpression. So, I tried the following column expression to extract the actual value of x: describe("evaluate('day1.x'," + ...

Property Accessing other properties
 hello i am new to asp.net and also c# and trying to learn some basic concepts now. I am reading article about the font propertyI am a little confused here. My question is Font property belong to WebControl class Font properties belong to FontUnit Class. How does the Font property access the font properties in the FontUnit ClassPlease if somebody could clarify this point for methanx Hi, As far as I can see, FontUnit represents the size of a font. So please look the following code.         Button bt = new Button(); // we create  a ...

Value property using FCKEditor in ATLAS is not updated, can't get Value
Hi,  I am using the ASP.NET integration of FCKEditor v2.2 inside an Atlas UpdatePanel.In a postback the editor's value is not updated and I can't get the value property of the control.  Is there any work around known?  Regards, HSHUeslei...

I use DataGird_ItemCreated Events and a droplist to DataGrid Cell,but I cann't let the droplist have a initial value , even I use SelectedValue property or SelectedIndex property
I use DataGird_ItemCreated Events and a droplist to DataGrid Cell,but I cann't let the droplist have a initial value , even I use SelectedValue property or SelectedIndex property protected void dgMain_ItemCreated( Object sender, DataGridItemEventArgs e) { if( e.Item.ItemType == ListItemType.EditItem) { DropDownList ddlPermissionCategory = new DropDownList() ; ddlPermissionCategory.ID = "ddlPermissionCategory" ; ddlPermissionCategory.DataSource = Business.AccountsTool.GetCategoryList() ; ddlPermissionCategory.DataTextField = &q...

Get the property value using ClassDefinition object
Hi all One question: With ClassDefinition, can I get the value of the name or tag properties of an object not instantiated yet? Yes. You might need to use FindClassDefinition() to obtain the ClassDefinition object that you want. Hern�n Castellani wrote: > Hi all > > One question: With ClassDefinition, can I get the value of > the name or tag properties of an object not instantiated > yet? Since an uninstantiated variable doesn't have a value, I'm guessing you mean the initial value. Once you get the ClassDefinition, you can loop through to find ...

User Control Property Persistence
I have a user control that's rendered in a data bound List View, for example:<asp:ListView ID="ListBuildings" DataSourceId="ListDataSource" runat="server"><ItemTemplate>    <custom:Rater ID="Rater" BuildingId='<%# Eval("BuildingId")%>' runat="server" /></ItemTemplate></asp:ListView> I set a custom property on my user control called BuildingId, but on post backs I'm not finding the BuildingId property set to what I set it to in the through the list view's databind...

Web resources about - Property access must assign to the property or use its value - asp.net.getting-started

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Chinese property firm Yuhu hires ex-deputy premier Andrew Stoner
A Chinese-based property firm that has donated hundreds of thousands of dollars to Australian political parties has added former deputy premier ...

How property developers make windfall millions
Buy one thing, use spin and insider knowledge to get planning approval to turn it into something completely different and, hey presto, you've ...

$1M transformation takes property from hoarding hell to heavenly home in Brisbane’s inner city - The ...
A HOARDER’s hovel has been transformed in seven months from a stinking mess to a dream family home — because of the efforts of two determined ...

Real estate: Couples opting for discount weddings to get a foot on property ladder
WHEN it comes to saving up for a home, life can get in the way.

Property estates on former Perth school sites popular with buyers - PerthNow Search Search
CRAIGIE, about 24km from the CBD, is the site of Perth’s latest residential school conversion. The first 22 blocks at the site of the former ...

Chinese property firm Yuhu hires ex-deputy premier Andrew Stoner
A Chinese-based property firm that has donated hundreds of thousands of dollars to Australian political parties has added former deputy premier ...

Esperance Bushfire: Reports of property losses as fires rage in south WA
Fast-moving, out-of-control bushfires threaten lives and homes in the Esperance region in southern Western Australia.

Seattle startup ranks every property in King County based on its redevelopment potential
... best properties to buy and what to build there. The 1-year-old company, Everyhome, already operates a website where buyers can bid on any property, ...

Resources last updated: 11/21/2015 7:08:12 AM