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 840713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:40:15+00:00 2026-05-15T05:40:15+00:00

This this code: SELECT SUBSTRING(posted,1,4) as year FROM styles reader = cmd1.ExecuteReader(CommandBehavior.CloseConnection); reader.Read(); Response.Write(reader[0].ToString());

  • 0

This this code:

SELECT SUBSTRING(posted,1,4) as year FROM styles
reader = cmd1.ExecuteReader(CommandBehavior.CloseConnection);
reader.Read();
Response.Write(reader[0].ToString());

I only get the string “System.Byte[]” printed out. How come?

If I use the software Mysql Query Browser I get the actual string from my database.

I understand that “Byte[]” is an arraylist but how do I convert this to a pure string?

The “posted”-field in my database contains a date like “2010-04-04 13:23:00” and I want to get only the year by using SUBSTRING.

  • 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-15T05:40:16+00:00Added an answer on May 15, 2026 at 5:40 am

    The correct query is

    SELECT DISTINCT SUBSTRING(CONVERT(varchar, posted, 111),1,4) as year FROM styles
    

    It equals to

    SELECT STR(YEAR(posted)) as year FROM styles-- YEAR returns int statement
    

    First argument is converted, than substring extracted.
    111 – the convertion format: http://www.mssqltips.com/tip.asp?tip=1145

    Also try

    reader["year"].ToString();
    

    as far as you use this alias.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i develop this code: SELECT COUNT(NewEmployee.EmployeeID), NewEmployee.EmployeeId,EmployeeName FROM NewEmployee INNER JOIN NewTimeAttendance ON NewEmployee.EmployeeID
I use this code to select password field from the sql server 2012 db,
I have this code here printf '$request1 = select * from whatever where this
I got this Doctrine query: select upper(substring(e.name, 1, 1)) first_letter from Application\Models\Exercise e group
I have this code for a select box which is being displayed by the
This code doesn't work: return this.Context.StockTakeFacts.Select(stf => ((stf.StockTakeId == stocktakeid) && (stf.FactKindId == ((int)kind)))).ToList<IStockTakeFact>();
This code didn't works as expected. I want to select all the posts that
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
I have this code <Select> <option value=-1>Select</option> <option value=6>kasper </option> <option value=13>adad </option> <option
I currently am using this JavaScript code snippet to select 3 checkboxes at a

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.