Link to home
Start Free TrialLog in
Avatar of ANINDYA
ANINDYAFlag for India

asked on

DatetimePicker taking arbitary time

Experts
Please see the attached image.
Can you please  tell me how to solve it.
Thanking you,
Anindya
private void checkBox_UpdateDateofPurchase_CheckedChanged ( object sender, EventArgs e )
            {
            if (label6.Text != string.Empty)
                {
                    int lot;
                    if (Int32.TryParse(textBox_lotNo.Text, out lot))
                    {
                        decimal price;
                        if (decimal.TryParse(textBox1.Text, out price))
                        {

                            //string previousNameofItem;
                            //previousNameofItem = label6.Text;
                            //DateTime DateOfPurchase;
                            //DateOfPurchase = dateTimePicker_DateOfPurchase.Value;
                            string NameofItem;
                            NameofItem = textBox_FilmName.Text;
                            Int32 Dealer_ID;
                            Dealer_ID = Convert.ToInt32(textBox_DealerID.Text);
                            string DateOfPurchase;
                            DateOfPurchase = dateTimePicker_DateOfPurchase.Value.ToString();
                            string Typefilm;
                            Typefilm = comboBox_Type.SelectedValue != null ? comboBox_Type.SelectedValue.ToString() : comboBox_Type.Text;

                            //Typefilm = comboBox_Type.SelectedValue.ToString();
                            string Language1;
                            Language1 = comboBox_Language.SelectedItem != null ? comboBox_Language.SelectedValue.ToString() : comboBox_Language.Text;
                            string YearOFRease;
                            YearOFRease = comboBox_YearOfRelease.SelectedValue != null ? comboBox_YearOfRelease.SelectedValue.ToString() : comboBox_YearOfRelease.Text;
                            string FilmCategory;
                            FilmCategory = comboBox_FilmCategory.SelectedValue != null ? comboBox_FilmCategory.SelectedValue.ToString() : comboBox_FilmCategory.Text;
                            string Actors_Name;
                            Actors_Name = textBox_ActorNames.Text;
                            string Actress_Name;
                            Actress_Name = textBox_ActressName.Text;
                            string Producer_Name;
                            Producer_Name = textBox_ProducerName.Text;
                            string Director_Name;
                            Director_Name = textBox_directorName.Text;
                            string StoryWriter_Name;
                            StoryWriter_Name = textBox_StoryWriterName.Text;
                            string ScriptWriter_Name;
                            ScriptWriter_Name = textBox_ScriptwriterName.Text;
                            decimal Price;
                            Price = Convert.ToDecimal(textBox1.Text);
                            Int32 lotNo;
                            lotNo = Convert.ToInt32(textBox_lotNo.Text);

                            Update_DateOfPurchase(NameofItem,DateOfPurchase, Dealer_ID, Typefilm, Language1, YearOFRease, FilmCategory, Actors_Name, Actress_Name, Producer_Name, Director_Name, StoryWriter_Name, ScriptWriter_Name, Price, lotNo);
                            Show_Distinct_Film_Name();
                        }
                        else
                        {
                            MessageBox.Show("Please enter a valid Price of the Item", "Price is requiered", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        }
                    }
                    else
                    {
                        MessageBox.Show("PLease enter a valid Lot no of the Item", "Lot no is required", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    }
                }
            else
                {
                MessageBox.Show ( "Please select a Film/Music Album Name which you want to Edit/Update", "Click on the Film/Music Album Name", MessageBoxButtons.OK, MessageBoxIcon.Error );
                }

            }

        private void Update_DateOfPurchase(string NameofItem,string DateOfPurchase, int Dealer_ID, string Typefilm, string Language1, string YearOFRease, string FilmCategory, string Actors_Name, string Actress_Name, string Producer_Name, string Director_Name, string StoryWriter_Name, string ScriptWriter_Name, decimal Price, int lotNo)
        {
            using (SqlConnection con = new SqlConnection(connectionstring.Connection))
            {//update Table_FilmDetail set Dealer_ID=@parameter1 where NameofItem=@parameter2  and Typefilm=@paramTypefilm and Language1=@paramLanguage1 and YearOFRease=@paramYearOFRease and FilmCategory=@paramFilmCategory and Actors_Name=@paramActors_Name and Producer_Name=@paramProducer_Name and Director_Name=@paramDirector_Name and StoryWriter_Name=@paramStoryWriter_Name and ScriptWriter_Name=@paramScriptWriter_Name and Price=@paramPrice and lotNo=@paramlotNo
                string query = "update Table_FilmDetail set DateOfPurchase=@paramDateOfPurchase  where NameofItem=@parameter2 and Dealer_ID=@parameter1  and Typefilm=@paramTypefilm and Language1=@paramLanguage1 and YearOFRease=@paramYearOFRease and FilmCategory=@paramFilmCategory and Actors_Name=@paramActors_Name and Producer_Name=@paramProducer_Name and Director_Name=@paramDirector_Name and StoryWriter_Name=@paramStoryWriter_Name and ScriptWriter_Name=@paramScriptWriter_Name and Price=@paramPrice and lotNo=@paramlotNo";
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@parameter1", Dealer_ID);
                    cmd.Parameters.AddWithValue("@parameter2", NameofItem);
                    cmd.Parameters.AddWithValue("@paramDateOfPurchase", DateOfPurchase);
                    cmd.Parameters.AddWithValue("@paramTypefilm", Typefilm);
                    cmd.Parameters.AddWithValue("@paramLanguage1", Language1);
                    cmd.Parameters.AddWithValue("@paramYearOFRease", YearOFRease);
                    cmd.Parameters.AddWithValue("@paramFilmCategory", FilmCategory);
                    cmd.Parameters.AddWithValue("@paramActors_Name", Actors_Name);
                    cmd.Parameters.AddWithValue("@paramProducer_Name", Producer_Name);
                    cmd.Parameters.AddWithValue("@paramDirector_Name", Director_Name);
                    cmd.Parameters.AddWithValue("@paramStoryWriter_Name", StoryWriter_Name);
                    cmd.Parameters.AddWithValue("@paramScriptWriter_Name", ScriptWriter_Name);
                    cmd.Parameters.AddWithValue("@paramPrice", Price);
                    cmd.Parameters.AddWithValue("@paramlotNo", lotNo);
                    con.Open();
                    SqlDataReader reader = cmd.ExecuteReader();
                    MessageBox.Show("Updated");
                }
            }
        }

Open in new window

error.JPG
Avatar of Ayman Aboualnour
Ayman Aboualnour
Flag of Egypt image

You can change the format of this  column:
right click on your datagridview
click edit columns
select the date column (DateofPurchase)
seek for the property DefaultCellStyle
click the modify button
seek for the fomat property and give it value dd-MMM-yyyy

reply me if it is not clear
Rgards,
Ayman
Avatar of ANINDYA

ASKER

Expert
that  column (DateofPurchase) is not coming .while editing.
Please  see the attached image.
Thanking you,
anindya
error.JPG
try this after you fill the datatable:

dataGridView1.Columns["DateofPurchase"].DefaultCellStyle.Format = "dd-MMM-yyyy";
Avatar of ANINDYA

ASKER

Expert  aymoon80
Please see the attached image.
Take regards
Anindya
error.JPG
before assigning data source in

dataGridView1.DataSource = ....

Put this line:
            dataGridView1.AutoGenerateColumns = true;

Avatar of Cycloner
Cycloner

select col1,col2,convert(varchar, dateofpurchase,3),col5... from Table_FilmDetail


try this sql query :D
Avatar of ANINDYA

ASKER

Expert aymoon80
Please see the attached image.
The problem is still there.
Take regards,
Anindya
error.JPG
Avatar of ANINDYA

ASKER

Expert cycloner
Please see the attached image.
Here I tried your sql query .
The o/p is not as expected.
Thanking you,
Take regards,
Anindya

cycloner.JPG
Avatar of Arana (G.P.)
is it possible that you might be filling your datagrid somewhere else?
ANINDYA;
Please check your other post that I answered.

Regarding to this question, I don't really understand the situation of the problem.
Please you renounce again your problem.
Is your problem about date? time? Date and time? Of what? for what? Can you explain further more so that readers may analyse the issue.
Avatar of ANINDYA

ASKER

Expert Systan
I am using sql server 2005 .
there is datatype datetime.
now in datetime it not only saves the date but also the time .
I want to save the date only not the time.
For more simplicity I would like to tell you that is in sql server 2008 there is a data type date .
it only saves the date not the date and as well as time .
How to achieve that objective .
that is only date should be saved in my table not the time .
Thanking you
Anindya
ASKER CERTIFIED SOLUTION
Avatar of systan
systan
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's hard to code between these two .Net connection strings;
MySql and Sql
My eye's troubled looking your orginal code and my test code,  converting from mysql to sql,   that's why we have reach a so far discussion of the problem.

Anyway I've attached a small .zip file, and it's ready for SqlConnections, NOT MySql.
Just open the file that has an extension of .csproj


I have already commented on your DATEpicker post,  please understand of whay I am trying to say.


Thanks



Systan
ANINDYAcomboGrid.zip
Oh, NO!, I though this was the other link, wrong tab.
OK;
I have my comments.
Avatar of ANINDYA

ASKER

Expert Systan
I have to go to home now .
so now I can not do it now.
Tomorrow I will try it.
Please do not think I am not responding to your suggestions.
Thanking you,
Anindya
How is the coding?
Avatar of ANINDYA

ASKER

Expert Systan
I am sorry for not answering today morning to your datetime case .
Actually datetime is working fine by the ToShortDateString()
Thanks for answering .
Expert Systan if possible kindly consider on my two requests.
At least on one that  is 3 tier architechture.
it is too much important for me on web form as well as winform.
Kindly and sympathetically think on this .
I can understand you might be too busy with your own projects
But if you can it will be great for me.
I badly need it.
The kind of expertise level you possess you might not have to face a lot of problem.
Again Thanking you,
Take my regards,
if possible please view following link if you have a bit of time.
https://www.experts-exchange.com/questions/26414264/DatagridviewColumnButton-Color-setting.html
Thanking you again,
Anindya Chatterjee
Bangalore
India
Avatar of ANINDYA

ASKER

Expert Systan
Thanks for listening me.
Thanks for answering me.
Hope to get your help in future too.
Thanking you,
Anindya Chatterjee
Bangalore
India