C# :: Retrieve Datetime From SQL?
Nov 4, 2014
i have saved my data in sql and i can retrieve them except datetime i can't retrieve ,, this is my code
SqlCommand cmd1 = new SqlCommand("select ID,name,carplatnumber,cartype,expiredate,badgtype from [ID-personal] where id like('" + textBox1.Text + "%')", cn);
SqlDataReader dr1;
[Code].....
View 11 Replies
ADVERTISEMENT
Nov 25, 2014
i have a form in which i have a field date of birth , and a textbox to fill date of birth , when a person fills his date of birth like 01/01/1990 , then it will be saved into database , and when i retrieve this date form database then this comes 01/01/1990 12:00 AM , i want only date part from it.
This is my form to fillup date of birth
form.aspx
<tr>
<td width="30%">
Date of Birth
<br />
</td> <td style="width: 1px">
:<asp:TextBox ID="txtDateofBirth" runat="server" placeholder="dd/mm/yyyy"></asp:TextBox>
</td> <td class="td2">
</td>
</tr>
this is code for form.aspx.cs
SqlCommand cmd = new SqlCommand("insert into ApplicantForm(NameofApplicant, dateofbirth)" +
"values( @NameofApplicant, convert(Datetime, @dateofBirth, 103)", con);
cmd.Parameters.AddWithValue("@dateofBirth",txtDateofBirth.Text);
this is code for print of this date of birth
print.aspx
<asp:Label ID="txtDOB" runat="server" ></asp:Label>
this is code print.aspx.cs
SqlCommand cmd = new SqlCommand("Select * from ApplicantForm Where ApplicantId=" + ((Request.QueryString["ApplicantId"])) + "", con);
dr = cmd.ExecuteReader();
txtDOB.Text = dr["dob"].ToString();
View 2 Replies
View Related
Aug 5, 2013
I'd like to get a a field name "eventDateTime" from a DB table and its storage is datetime year to fraction (3) . I have created a function return results like this but i put its type as a int:
int Status::GetEventFromSQL(){
int j = 0;
int eventTime = 0;
MYSQL_ROW myROW;
MYSQL_RES *myRES = NULL;
[code]....
"eventTime " is also declared in another sheet .h as an int. In execution i have a big and negative number ; I know that's because of the int type but i'm bigenner in C++...
View 2 Replies
View Related
Jun 30, 2014
I currently have a DatePicker in my xaml forum. In my constructor and class I have my dates as a DateTime object. I am currently trying to get my datepicker date to be passed into my constructor or maybe I have to convert the datepicker to a datetime object?
private void btnSave_Click(object sender, RoutedEventArgs e)
{
DateTime xxx = new DateTime();
xxx = Convert.ToDateTime(dateCurrent.SelectedDate);
//validate registration form
lifter = new User(txtFirstName.Text, txtLastName.Text, txtStartWeight.Text, genderStatus, xxx);
View 4 Replies
View Related
Oct 30, 2014
I have a DateTime field on a database it looks like this :
2014-10-21 14:34:37.697
I want to use it, as is, in an UPDATE statement something like:
UPDATE PayrollRuns SET IsProcessed = 'True' WHERE Date_Time_Triggered = '2014-10-21 14:34:37.697'
I must have the exact date & time as that uniquely identifies the record.
The problem I'm having is getting it off the database and into an C# variable without it being changed.
I can get it into a string but it changes it becomes:
21/10/2014 14:34:37
I've got it in an object. I've tried:
string date_Time_Triggered = databasesRow["Date_Time_Triggered"].ToString();
//
//and
//
var date_Time_Triggered = databasesRow["Date_Time_Triggered"];
[Code] ....
View 3 Replies
View Related
Sep 12, 2014
I am trying to insert values from a form into my SQL database. Two of the fields in the SQL database are of type DateTime.
When trying to insert I am receiving the error "Conversion failed when converting date and/or time from character string."
The relevant code is as follows:
DateTime saveNow = DateTime.Now;
string sqlFormattedDate = saveNow.ToString("yyyy-MM-dd HH:mm:ss");
conn.Open();
[Code] ....
The table layout:
View 5 Replies
View Related
Sep 1, 2014
I am converting unix timestamp to datetime format like this:
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
static readonly double MaxUnixSeconds = (DateTime.MaxValue - UnixEpoch).TotalSeconds;
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) {
return unixTimeStamp > MaxUnixSeconds
? UnixEpoch.AddMilliseconds(unixTimeStamp)
: UnixEpoch.AddSeconds(unixTimeStamp);
}
use it:
Console.WriteLine("From UNIX do datetime 1300123800440 : " + UnixTimeStampToDateTime(1300123800440));
output: 14.03.2011 5:30 PM
Now i would like to have function which convert it back to unix timestamp but unfortuently my new function is cutting down last 3 digits for instance:
public static long UnixTimestampFromDateTime(DateTime date) {
long unixTimestamp = date.Ticks - new DateTime(1970, 1, 1).Ticks;
unixTimestamp /= TimeSpan.TicksPerSecond;
return unixTimestamp;
}
after use of it i am retrieving:
Console.WriteLine(UnixTimestampFromDateTime(Convert.ToDateTime("14.03.2011 5:30 PM")));
result:
1300123800
View 14 Replies
View Related
Jun 10, 2013
I am getting this error whenever I leave my drop down lists blank: "String was not recognized as a valid DateTime". My code is below:
aspx:
asp:DropDownList ID="cboDay" runat="server" Width="55px" Height="32px" AppendDataBoundItems="true">
<asp:ListItem></asp:ListItem></asp:DropDownList >
<asp:DropDownList ID="cboMonth" runat="server" Width="80px" Height="30px" AppendDataBoundItems="true">
[Code]....
View 2 Replies
View Related
Jun 28, 2012
I retrieve a null value from a nullable sql datacolumn but when I pull it into a property it automatically gets the current datetime.
How will I go about making sure that this value returns a null and not the currentdatetime.
View 1 Replies
View Related
Jan 1, 2014
I have an application in C sharp that searches for a record in a sql database using a datetimepicker,the output is displayed in a datagridview.When I execute it I got a blank datagridview with empty columns.I can not view the content and I don't get any error message.
Here is my code:
DataTable dt=new dataTable();
SqlDataAdapter sda=new sqldataadapter("select * from Delivery where convert
(char(20),Delivery_Date,112)='"+ dateTimePicker1.value.Date,con);
//con is sqlconnection
Sda.Fill(dt);
Datagridview1.DataSource=dt;
View 1 Replies
View Related
Jun 8, 2013
How do I convert date in integer format to DateTime without using DateTime?
I have tried:
Regex regex = new Regex(@"^(0[1-9]|1[012])(0[0-9]|1[0-9]|2[0-9]|3[01])(1[789]|[2-9][0-9])dd+$");
if (regex.IsMatch(txt_fromdate.Text) == true)
{
DateTime dt = DateTime.ParseExact(txt_fromdate.Text, "MMddyyyy", null);
}
View 1 Replies
View Related
Aug 28, 2013
In c89/90 is there a way to retrieve a pointer from stack or whatever that would behave as this would once cast to the correct type? This is more of a curiosity than a requirement.
View 6 Replies
View Related
Jun 16, 2014
I am looking to retrieve data from a USB device, this device is a fingerprint scanner. Because I bought it online and wasn't reading carefully enough, drivers and other installation programs weren't included. Send it back? Nah . . .
I want to see if it is possible to retrieve data from this device. To be honest, I don't even know if it's possible, but I would love to give it a whack.
I looked into making INF files and things Microsoft has put out, but I honestly don't know where to start simply because I have absolutely no experience doing this. I have a program set up to organize the data and such, I just need to find a way to actually get it.
What should I research and look into? Are drivers necessary?
Here is a little more information :-)
I want to save data from a fingerprint scanner.I bought a fingerprint scanner, but nothing came with it (drivers, software, etc.). I decided to not return it and see what fun I could have.
I have no code written up yet (mainly because I don't know where to start). But I looked into the device a little...Microsoft recognizes it as a "Fingerprint Scanner" but is still considered unrecognized.I have the USB identifier (at work right now, don't have it on hand)...
Is it even possible to communicate with the device without the initial drivers.Do I really need drivers for the device, or can I communicate with it as it is now.If I do need drivers, where should I start?What should I look into to get communicating with the device?
View 6 Replies
View Related
Sep 10, 2013
I am trying to retrieve an image from its URL as an array where each box represents the pixel value of the image.
View 3 Replies
View Related
Feb 25, 2013
I was wondering if i had to say simply retrieve data from a server whether it be simple plain text for variables or download whole files (FTP), what would be the best method for this? I would imagine there is a pretty big difference between retrieving text and downloading files but im just wondering what the best thing would be to research for both.
View 3 Replies
View Related
Feb 25, 2013
I'm trying to retrieve the Player object from my hash table so I can edit the content of that object. Here is what I have.
Player* HashTable::retrieve(char * key, Player& aPlayer) {
//calculate the retrieval position (the index of the array)
size_t index = calculateIndex(key);
//search for the data in the chain (linked list)
node * curr = table[index];
char id[100];
[Code] .....
Here I'm calling the retrieve and I need to return a pointer of that object.
Player* PlayerDB::FetchPlayer(char* name) {
Player* info = new Player();
out << "Fetching player " << """ << name << "" -- ";
if(h.retrieve(name, *info)) {
out << "Success!" << endl;
[Code] .....
And here is my call in main.
Player* outPlayer = NULL;
outPlayer = pdb.FetchPlayer("Sappho");
if (outPlayer != NULL) {
outPlayer->LevelUp();
}
I'm just trying to change the actual level of the player using the LevelUp function, but right now it is not making that change. I've been told I need to return a reference of the object in my retrieve function, but I thought that was what I was doing already.
View 3 Replies
View Related
Jul 15, 2014
Basically, I'm trying to figure out the index in an array from a pointer that is returned by either bsearch or lfind.
void *val;
void *begin = (char *)v->elems (I need to use this separate variable)
Then, I call on either search, which seems to be working fine...
val = bsearch(key, begin, v->count, v->elemsz, cmp);
I'm trying to do the following:
index = *(int*)((char*)value_to_find - (char*)start_ptr)/sizeof(cv->elemsz)
However it segfaults everytime I do this. My logic is that I cast both void pointers to type of char*, then subtract the distance b/w the pointers since you can't do pointer arithmetic on void. I divide this by the size of each element to return the index, which needs to be cast to an int. What am I missing here?
View 1 Replies
View Related
Feb 17, 2014
I wanted to retrieve all rows from database and display in listview using list<string>
con.Open();
MySqlCommand view = new MySqlCommand("Select Cust_ID,Fname,Mname from Customer;", con);
MySqlDataReader v1 = view.ExecuteReader();
while (v1.Read()) {
for (int i = 0; i < v1.FieldCount; i++){
result.Add(v1["Cust_ID"].ToString());
[Code] .....
View 4 Replies
View Related
Jan 26, 2015
How to shorten it but it would need the user to set a variable's value and use that variable to call the array element.
int main() {
const int size = 3;
int choice;
[Code].....
View 6 Replies
View Related
Feb 25, 2015
how would i recieve the latitude and longitude from this xml
XmlTextReader reader = new XmlTextReader
("http://maps.googleapis.com/maps/api/geocode/json?address=" + postcode);
it should reurn the array
the php code is :
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . $search_code . '&sensor=false';
$json = json_decode(file_get_contents($url));
$lat = $json->results[0]->geometry->location->lat;
$lng = $json->results[0]->geometry->location->lng;
return array($lat,$lng);
View 6 Replies
View Related
Sep 23, 2012
I used to retrieve IP and NIC information by querying windows registry. Now I'm trying to use GetAdapterAddresses() API. Using GetAdapterAddresses() to get IP is not that easy, I need to dig a long deep as I check some examples so far, anyways my question is: Calling this API will return success on all versions of Windows ie: 32bits & 64bits ?
Though Microsoft has not opened any source, where this API is actually retrieving Windows IP information.?. Is it reading Registry or some windows file.
View 6 Replies
View Related
Aug 20, 2014
I have a class I use to store column data read from delimited text files.
Code:
class column_data {
// class functions here
public:
// initialize class members
column_data()
: header(""),
[Code] ....
Each column is read into the vector of string. Next the string data is copy converted to the vector of double or the vector of int depending on the data type. There can also be additional transformations of the data (normalization, scaling, etc) and the transformed data is copied to the transformed_double_data vector. I do end up with multiple copies of the data, but I can clear some of the vectors if I don't need all the versions of the data anymore. Each column object goes into a container like a vector of objects or map of objects depending on how I need to access the column data.
There are functions that calculate statistics on the data in the columns and the results are assigned to the object variables like validate_r2. There are separate statistics for each column, so it seems logical to store the results in the column object. This works well for statistics like validate_r2 (pearson's correlation coefficient).
The current issue is that I have other statistics like "pw50" that I need to calculate and store. The statistic is the percent within +/- 50 units and the request for pw50 is passed in from the command line. The issue is that there could be several of these and they can have more or less any value like, pw50, pw75, pw100, etc. Storing data like this doesn't fit into my scheme very well because I can't pre-declare a variable to hold the result for every possible option. I don't know in advance how many, if any, of these there will be. I was thinking of adding two vectors, one of string and one of double,
Code:
class column_data {
public:
// initialize class members
column_data()
: header(""),
type(""),
use(""),
validate_r2(0.0),
[Code] ....
For each of this type of statistic requested, I would push_back a label into the string vector and then put the result into the parallel position in the double vector. This seems like I would work, but there are probably some things that could be done with pointers that might be better. Another option would be a vector of objects where each object had a string value for the label and a double for the result. That would be more bullet proof as far as keeping the label and value together, but I have not ever nested objects in a class like that so I thought I would post. I don't know the syntax for declaring an object of class_b inside the definition of class_a. The need is to provide dynamic storage for an unspecified number of these statistics and a reliable way to retrieve the values using the label.
View 1 Replies
View Related
Feb 11, 2014
I am trying to read a tab delimited file containing 8 columns and store each element of the column as an 1-dimensional array. Though the program prints the strings correctly as in the commented printf but it doesn't give me first_col[0] value and so on. My code is as follows:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
FILE *int_file1;
int BUF = 1024;
[Code]...
The inputfile test.txt has the following elements:
34932 13854 13854 2012-01-07
172098 49418 53269 2012-01-07
-
-
-
View 7 Replies
View Related
Nov 23, 2013
I created a simple program that writes some text to two different text files. how to create a program that would retrieve the information from those two files, and put them in a single file, first the content of input1 and then the content of input2. how to do this. Here is the program that I created that creates the two files.
#include <iostream>
#include <fstream>
#include <string>
int main() {
using namespace std;
string input1;
ofstream fout("input1.txt");
[Code]...
View 3 Replies
View Related
Jul 25, 2013
I've created a text file with the numbers from 1-450. After writing code to retrieve and print out the contents in the text file, the compiler only printed out the numbers 124-450. Is there a reason why this is happening?
View 19 Replies
View Related
Feb 9, 2013
I am working on a linked list that instead of the traditional integer value for a data, i'm using my own class. Unfortunately when i do this, i cant seem to retrieve my data from my Node.
#include "Customer.h"
class Node {
// TO DO:: Fill in.
//Constructors and destructor
public:
Node();
Node(int atime, int ttime);
Node(int atime, int ttime, Node* nd);
[Code] .....
In my main code, I've been trying something like
Node* c = new Node(1,2)
Customer x = c->cust; // or Customer x = c->get_cust();
cout<<x.get_atime()<<endl;
cout<<x.get_ttime()<<endl;
It should be displaying 1 and then 2, but just outputs 0 and 0.
View 1 Replies
View Related