Click here to Skip to main content
15,891,912 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
dear sir i want to printprieview ,the selected items from data grid view and also to print the selcted items with title provided by me and date i have searched lots of querry showing this results but they very much confusing ,and another thing is that i have use datetimepicker for selecting date but when i select the date and when date is saved its in dd-mm-yyyy hh-mm-ss so when i searched in output usng date no records are found bcoz it searches date which is in string format i want to use date in my form with only dd-mm-yyyy values stored
i have written commands in sql for date is {[DATE] [nvarchar](40) NULL,}and in c# i am binding date as

C#
{
   dateTimePicker1.DataBindings.Clear();
   dateTimePicker1.DataBindings.Add("Text", dv, "DATE");
}

for save date on save button
C#
{
cmd = new SqlCommand("insert into REGISTRY values(@CUSTUMER,@DATE)",con);
cmd.Parameters.Add("@DATE", SqlDbType.NVarChar, 20);
cmd.Parameters["@DATE"].Value = dateTimePicker1.Value;
}

please it would be very great if you help me i am new to software programing and i am getting how to solve it.
Posted
Updated 4-Aug-12 21:05pm
v2
Comments
Christian Graus 5-Aug-12 2:40am    
If you're new to software programming, and you want to be a programmer, learn C# properly before you start to worry about things like SQL and printing. If you ask enough questions here, you can probably cobble together some code that runs, although you won't understand it. That's not the path to being a programmer.
adnanhakim110 5-Aug-12 3:03am    
sir i know the c# language but sir there are some silly mistakes and some lack of exprience thats why i connected to codeproject for gaining the information from the senior developers ,iknow code for print preview and print setup but i want to prnt from data grid view wch is not happening

I think that you can use this.

C#
cmd.Parameters["@DATE"].Value = String.Format("dd-mm-yyyy",dateTimePicker1.Value);


And read more about SQL and Strings. It will help you...

Thanks.
 
Share this answer
 
Comments
adnanhakim110 14-Aug-12 2:09am    
thank you sir for your help but sir i have tried the code but sir instead of saving the date in dd-mm-yyyy format the the the data only shows dd-mm-yy which is in ""in your answer no date is saved
Tarun Mangukiya 14-Aug-12 9:13am    
Try this answer:
http://www.codeproject.com/Questions/188662/how-to-insert-date-in-SQL-SERVER-2008-using-C-NET

It is solved...
For Print and PrintPreview you can refer this articles...

Basic Text and Image Printing[^]

And

DataGridView Print/Print Preview Solution - Part II[^]

They will help you.

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900