Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:49:48+00:00 2026-05-23T16:49:48+00:00

I am trying to write VB.NET query without writing SQL stored procs. I have

  • 0

I am trying to write VB.NET query without writing SQL stored procs. I have already gotten many dataset text queries to work. But I am having trouble with getting this scalar query to work. All I want to do is to get the result of this T-SQL query. How can I code this successfully?

select (DateDiff(w, '1/1/' + '2011', getdate())) / 7 AS SELECTED_WEEK

(What this code does is it returns the current week of the year). And will this query above return the value as an integer datatype or string?

I tried your answers but it gave me this exception error:

System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is Closed.

Do you know what this means?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:49:48+00:00Added an answer on May 23, 2026 at 4:49 pm
    Dim result As Integer
    Dim sql As String = "select (DateDiff(w, '1/1/' + '2011', getdate())) / 7 AS SELECTED_WEEK"
    
    Using cn As New SqlConnection("your connection string here"), _
          cmd As New SqlCommand(sql, cn)
    
        cn.Open()
        result = Convert.ToInt32(cmd.ExecuteScalar())
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a sql query to the following (from this site http://sqlzoo.net/1b.htm
I'm trying to write a linq to object query in vb.net, here is the
I am trying to write an application that uses java.net.Socket. I have also written
I'm trying to write an ASP.NET MVC application where user privilege is based upon
I am trying to write a VB.NET alternative to a C# anonymous function. I
Encouraged by SO, I'm trying to write an ASP.NET site that uses OpenID for
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem
I'm trying to write a web page in .NET, using C# and NHibernate 2.1.
I am trying to write a Windows Form and ASP.NET C# front-end and MSAccess
I'm trying to write a log file from an ASP.NET application under IIS7, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.