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

  • Home
  • SEARCH
  • 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 8334785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:27:40+00:00 2026-06-09T03:27:40+00:00

When I try to run this code, I’m receiving this error: conversion failed when

  • 0

When I try to run this code, I’m receiving this error:

conversion failed when converting date and/or time from character string

I get the error on this line:

g_muallak_tarihi = DateTime.Parse(row_muallakt["Muallak_tarihi"].ToString());

To store values that are both dates and times or only dates, I use the DateTime data type. I’m not sure what to do. Do you have any ideas?

Here is my code:

public void cs_hmuallak()
{
    string cs_hmuallak = null;
    SqlConnection cnn;

    cs_hmuallak = @"Data Source= .\SQLEXPRESS; Initial Catalog=mydb;Integrated Security= True";

    cnn = new SqlConnection(cs_hmuallak);

    try
    {
        cnn.Open();

        {
                SqlDataAdapter da_muallakt = new SqlDataAdapter("SELECT M.Muallak_tutari FROM Muallak M INNER JOIN Hasar H ON M.Hasar_no= H.Hasar_no INNER JOIN Police P ON p.Police_no=h.Police_no where p.Acenta_kodu='"+cbx_acenta.Text+"' and p.Brans_kodu='"+cbx_brans.Text+"' and  M.muallak_tarihi<=(Select M.muallak_tarihi from muallak M where M.muallak_tarihi=(select max(muallak_tarihi) from muallak where muallak_tarihi<=@parameter)) and M.Muallak_tarihi=(SELECT max(M.Muallak_tarihi) FROM Muallak M INNER JOIN Hasar H ON M.Hasar_no= H.Hasar_no INNER JOIN Police P ON p.Police_no=h.Police_no where p.Acenta_kodu='"+cbx_acenta.Text+"' and p.Brans_kodu='"+cbx_brans.Text+"' and  M.muallak_tarihi<=(Select M.muallak_tarihi from muallak M where M.muallak_tarihi=(select max(muallak_tarihi) from muallak where muallak_tarihi<=@parameter)) ) ", cnn);

                da_muallakt.SelectCommand.Parameters.AddWithValue("@parameter",g_listetarihi.ToString("yyyy-mm-dd"));
                DataTable table_muallakt = new DataTable();
                da_muallakt.Fill(table_muallakt);
                foreach (DataRow row_muallakt in table_muallakt.Rows)
                {
                    if (row_muallakt["Muallak_tutari"] != DBNull.Value)
                    {
                        if (row_muallakt["Muallak_tarihi"] != DBNull.Value)
                        {
                            g_muallak_tarihi = DateTime.Parse(row_muallakt["Muallak_tarihi"].ToString());
                            g_muallak_tutari = int.Parse(row_muallakt["Muallak_tutari"].ToString());
                        }
                    }
                }                   
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}       
  • 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-06-09T03:27:41+00:00Added an answer on June 9, 2026 at 3:27 am

    Assuming that Muallak_tarihi is defined as a DATETIME column (which is should be as that’s what it is holding), all this work with converting to and from strings is not needed.

    You can simply use GetDateTime directly with the data reader in order to get it, or simply cast the value:

    g_muallak_tarihi = row_muallakt["Muallak_tarihi"] as DateTime;
    

    Additionally, the parameter you are using (@parameter) should also be a DATETIME – and simply passed in directly, instead of using ToString:

    da_muallakt.SelectCommand.Parameters.AddWithValue("@parameter",g_listetarihi);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code returns me an error whenever I try to run this code. Can
When i try to run this code i get the error: Warning: mysql_fetch_array() expects
I am getting a "Bus error" when I try to run this code compiled
I get this error: Image When i try to run this code: strComputer =
When I try to run this code, I get incorrect maximums and minimums. Could
I have the given view and template code, when i try to run this
This Java code compiles fine, but when I try to run it I get:
Thanks in advance. This is my sample code. Whenever i try to run it
I get this error FB is not defined when i try to run this
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)

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.