CodeConnect.Net Beta


   Explore    Entry   Register  Login  
windowsxp-general
access
windows-vista-mail
windows-vista-general
windowsupdate
windowsmedia-player
access-forms
windows-live-mail-desktop
windowsxp-help_and_support
access-queries
access-modulesdaovba
access-formscoding
windows-server-sbs
windows-server-general
access-reports
windows-vista-music_pictures_video
windowsce-platbuilder
windows-live-messenger
windows-terminal_services
windows-powershell
windows-server-active_directory
access-gettingstarted
windows-mediacenter
windowsxp-hardware
windowsxp-network_web
windows-64bit-general
windows-live-sync
windows-vista-hardware_devices
windows-inetexplorer-ie6_outlookexpress
windows-group_policy
windows-server-networking
windows-vista-installation_setup
windows-vista-networking_sharing
windowsxp-basics
access-tablesdbdesign
windowsxp-perform_maintain
windows-vista-performance_maintenance
windows-networking-wireless
windows-vista-file_management
windows-inetexplorer-ie6-browser
windows-server-dns
windows-server-update_services
windows-vista-security
windows-vista-administration_accounts_passwords
windows-vista-games
windows-file_system
access-activexcontrol
windows-live-foldershare
windows-live-photogallery
access-developers-toolkitode
access-conversion




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > starter_kits_and_source_projects.small_business_starter_kit Tags:
Item Type: Date Entered: 1/18/2007 1:44:52 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 8 Views: 54 Favorited: 0 Favorite
9 Items, 1 Pages 1 |< << Go >> >|
"craigton" <>
NewsGroup User
Parameterized slect command snippet1/18/2007 1:44:52 PM

0

Hi,

I insert the following snippet and receive th error message "Declaration expected" but I thought the "Dim cmd As New SqlCommand" was the declaration!  What am I missing!

 

Thanks in advance. 

Public Class Class1
    Dim cmd As New SqlCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CustomerID, CompanyName FROM Customers WHERE CompanyName LIKE @companyName"
cmd.Connection = conn
    ' Create a SqlParameter for each parameter in the stored procedure.
    Dim companyNameParam As New SqlParameter("@companyName", "a%")
cmd.Parameters.Add(companyNameParam)

End Class

"MIB426" <>
NewsGroup User
Re: Parameterized slect command snippet1/18/2007 2:05:35 PM

0

not sure if you have same issue, but have a look

http://news.umailcampaign.com/message/30539.aspx

 


James Wu (MIB426)
.NET is only way to go
MCP, MCSE, MCDBA, MCSD, MCAD
"craigton" <>
NewsGroup User
Re: Parameterized select command snippet1/18/2007 7:53:55 PM

0

Thanks for this but it doesn't seem to help - although I may be missing something obvious. The code shown above was a straight insert of the snippet into the class so I'm a bit bemused tha it produces an error which makes me suspect I've not done something very basic!
"smartinezpr" <
NewsGroup User
Re: Parameterized select command snippet1/23/2007 8:16:41 PM

0

Can you give more info what this .vb filename is is part to this smb. or you are creating the select statment below, the only thing i dont see is the connection string.
Santos Martinez, MCSE, MCDBA, MCTS, MCT
Windows Server System - SQL Server MVP
"craigton" <>
NewsGroup User
Re: Parameterized select command snippet2/8/2007 2:41:19 PM

0

Many thanks for your response. I've not been online for a while so apologies for not responding sooner.

The following is a code sample copied from Microsoft documentation (reference ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/8a929e96-2cf5-43a5-b5b7-c0a5a397bbc5.htm)

 

Imports Microsoft.VisualBasic

Public Class Class3
    Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("ReservationsDBConnectionString")
    Dim cmd As New System.Data.SqlClient.SqlCommand
    Dim rowsAffected As Integer

cmd.CommandText = "StoredProcedureName"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1
sqlConnection1.Open()
rowsAffected = cmd.ExecuteNonQuery()
sqlConnection1.Close() 
End Class
 

I get the error "Declaration expected" for each of the 6 lines before the End Class line. I am clearly missing something terribly simple!

"Matt Morrison"
NewsGroup User
Re: Parameterized select command snippet2/9/2007 10:34:55 PM

0

Hi there,

It's because you are not declaring a method i.e. you are trying to run code outside an event handler; try this...

Imports Microsoft.VisualBasic

Public Class Class3

    Dim sqlConnection1 As New System.Data.SqlClient.SqlConnection("ReservationsDBConnectionString")
    Dim cmd As New System.Data.SqlClient.SqlCommand
    Dim rowsAffected As Integer

    ' For security create a public method so it can be referenced from a class instance (you do not expose the class code this way)
    Public Function OpenConn()
        ' Call private method returning the integer value
        Return p_OpenConn()
    End Function

    Private Function p_OpenConn()
        cmd.CommandText = "StoredProcedureName"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = sqlConnection1
        sqlConnection1.Open()
        rowsAffected = cmd.ExecuteNonQuery()

        ' Now return your value and close the connection
        Return rowsAffected
        sqlConnection1.Close()
    End Function

End Class
 Hope that helps Smile
Cheers, Matt Morrison
Managing Director

OPAL Logic Ltd
Business Web: www.opallogic.co.uk
Personal Blog: www.mattshome.co.uk
"craigton" <>
NewsGroup User
Re: Parameterized select command snippet2/13/2007 11:19:29 AM

0

Matt,

Many thanks for this fulsome explanation - it's very helpful and greatly appreciated.

"Matt Morrison"
NewsGroup User
Re: Parameterized select command snippet2/13/2007 11:48:46 AM

0

Thanks for the kind comments, just glad to help...

Did it resolve your issue?  I think that you can mark the post as answered if it did; i'm happy to offer more help if required Smile


Cheers, Matt Morrison
Managing Director

OPAL Logic Ltd
Business Web: www.opallogic.co.uk
Personal Blog: www.mattshome.co.uk
"Matt Morrison"
NewsGroup User
Re: Parameterized select command snippet2/20/2007 9:33:34 AM

0

Hi, you marked your answer as correct instead of my answer (if I was correct!), I don't know if it makes a difference but I thought i'd mention it. Wink
Cheers, Matt Morrison
Managing Director

OPAL Logic Ltd
Business Web: www.opallogic.co.uk
Personal Blog: www.mattshome.co.uk
9 Items, 1 Pages 1 |< << Go >> >|





   
  Privacy | Contact Us
All Times Are GMT