Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0SQL error SQL error
Previous
 
Next
New Post
3/22/2009 12:25 PM
 

 Can anyone tell me what this error message means, and what to do to correct it.  Here is the code that has the error: 

"Operator '&' is not defined for types 'String' and 'System.Web.UI.Label"

 

--------------------------------------------------this is my code behiend---------------------------------------------------

 

    Partial Class DesktopModules_News_News

        Inherits Entities.Modules.PortalModuleBase

 

 

    Protected Sub ButtonInsertNews_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonInsertNews.Click

 

        Dim TabID As Label = formView1.FindControl("LblChoicedTab")

        Dim DropDownList1 As DropDownList = formView1.FindControl("DropDownList1")

        TabID.Text = DropDownList1.SelectedValue

        Dim Titre As TextBox = formView1.FindControl("TextBoxTitreNews")

        Dim Contenue As TextBox = formView1.FindControl("TextBoxContenueNews")

 

        Dim Connection As System.Data.SqlClient.SqlConnection

        Connection = New System.Data.SqlClient.SqlConnection

        Connection.ConnectionString = "server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40"

 

        Connection.Open()

        Dim Command As System.Data.SqlClient.SqlCommand

        Dim SQL As String

        SQL = "INSERT INTO [News](TabID,Titre,Contenue) VALUES('" & TabID & "','" & Titre & "','" & Contenue & "')"

        Command = New System.Data.SqlClient.SqlCommand(SQL, Connection)

        Command.ExecuteNonQuery()

    End Sub

    End Class

 
New Post
3/22/2009 1:05 PM
 

TabID is a control, not a string which can be joined to other strings using the "&" operator.

VALUES('" & TabID & "','"

should be

VALUES("' & TabID.Text & "',

There are similar issues in the same statement with Titre and Contenue which are both TextBox controls.

Also, please do not build SQL statements in this manner as you will go crazy trying to keep the double and single quotes straight and open your application to SQL injection hacks. Please look into using parameterized SQL queries and/or stored procedures.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0SQL error SQL error


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out