Click here to Skip to main content
15,885,842 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Insert Error Pin
Roger Wright17-Jan-04 4:42
professionalRoger Wright17-Jan-04 4:42 
GeneralRe: SQL Insert Error Pin
rahtrow21-Jan-04 7:56
rahtrow21-Jan-04 7:56 
GeneralGet list of Tables from Database Pin
dlgross16-Jan-04 11:22
dlgross16-Jan-04 11:22 
GeneralRe: Get list of Tables from Database Pin
Guillermo Rivero16-Jan-04 12:17
Guillermo Rivero16-Jan-04 12:17 
GeneralRelationship w/ External Table Pin
Jamie Nordmeyer16-Jan-04 6:48
Jamie Nordmeyer16-Jan-04 6:48 
GeneralRe: Relationship w/ External Table Pin
Arjan Einbu18-Jan-04 3:50
Arjan Einbu18-Jan-04 3:50 
GeneralRe: Relationship w/ External Table Pin
Jamie Nordmeyer19-Jan-04 4:57
Jamie Nordmeyer19-Jan-04 4:57 
GeneralStoring DateTime Format, C# MSSQL DateTime field Pin
AssemblySoft16-Jan-04 5:58
AssemblySoft16-Jan-04 5:58 
D'Oh! | :doh:
I am having trouble storing the date in UK format.
I have an aspx page with a DateTime Validator control - works ok.

If the Date Text field on the page is entered in US format: mm/dd/yyy my INSERT works fine. However iif the format is UK: dd/mm/yyyy, the INSERT fails.

So i got to thinking i should be formatting the date myself after it passes through the Validator.

i tried the code below:

dt = Convert.ToDateTime(txtBirth.Text);
output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
values.Add("'" + output + "'");

Is this the correct approach? (full listing shown below)

If i do: //values.Add("'" + txtBirth.Text + "'");
and the Date is in US format it works fine, but fails for UK.


your help would be greatly appreciated...

Carl


Full Listing + stuff i've tried:

SqlConnection con;

string sql;

SqlCommand cmd;

StringBuilder sb = new StringBuilder();

ArrayList values = new ArrayList();

sb.Append("INSERT INTO [Users] ");

sb.Append("(UserID,Login,Password,FirstName,LastName,PhoneNumber,Email,Address,");

sb.Append(" MobileNumber, DateOfBirth,IsAdministrator) ");

sb.Append("VALUES ('{0}', '{1}', '{2}', '{3}','{4}','{5}','{6}','{7}','{8}',{9},{10})");


values.Add(Guid.NewGuid().ToString() );

values.Add(txtUser.Text);

values.Add(txtPwd.Text);

values.Add(txtFName.Text);

values.Add(txtLName.Text);

values.Add(txtPhone.Text);

values.Add(txtEmail.Text);

//values.Add(0);





if(txtBirth.Text != string.Empty)

{

//test vars

string output="No Output";

DateTime dt;

dt = Convert.ToDateTime(txtBirth.Text);
output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
values.Add("'" + output + "'");



//Test Blocks
//block 1
//DateTime dtNow = DateTime.Now;
//values.Add("'" + dtNow + "'");

//block 2
//values.Add("'" + txtBirth.Text + "'");

//block 3
//values.Add("'27/11/1999'");


//block 4
//storing the date & time local to the client
//DateTime dt;
//dt = DateTime.Now;
//string output = dt.ToString("G",DateTimeFormatInfo.CurrentInfo);
//values.Add("'" + dt + "'");



//block 5
//dt = Convert.ToDateTime(txtBirth.Text);
//output = dt.ToString("d",DateTimeFormatInfo.InvariantInfo);
//values.Add("'" + output + "'");

//block 6
//values.Add("'" + txtBirth.Text + "'");
//test stuff



Label1.Text = output;

}

else
values.Add("Null");


GeneralRe: Storing DateTime Format, C# MSSQL DateTime field Pin
Mike Dimmick16-Jan-04 12:52
Mike Dimmick16-Jan-04 12:52 
GeneralRe: Storing DateTime Format, C# MSSQL DateTime field Pin
Atilla Ozgur19-Jan-04 10:41
Atilla Ozgur19-Jan-04 10:41 
GeneralRe: Storing DateTime Format, C# MSSQL DateTime field Pin
gpa200022-Jan-04 0:58
gpa200022-Jan-04 0:58 
GeneralSQL Named Pipes Pin
Paul Watson15-Jan-04 23:57
sitebuilderPaul Watson15-Jan-04 23:57 
GeneralRe: SQL Named Pipes Pin
Mike Dimmick16-Jan-04 3:26
Mike Dimmick16-Jan-04 3:26 
Generalfinding databases Pin
fotis84115-Jan-04 10:03
fotis84115-Jan-04 10:03 
GeneralRe: finding databases Pin
Anonymous15-Jan-04 20:33
Anonymous15-Jan-04 20:33 
GeneralInserting and Updating BLOBS Pin
Guinness4Strength14-Jan-04 18:25
Guinness4Strength14-Jan-04 18:25 
GeneralRe: Inserting and Updating BLOBS Pin
Mike Dimmick16-Jan-04 3:31
Mike Dimmick16-Jan-04 3:31 
GeneralRe: Inserting and Updating BLOBS Pin
Guinness4Strength16-Jan-04 3:32
Guinness4Strength16-Jan-04 3:32 
GeneralCross Database insert procedure Pin
Ai_ling7914-Jan-04 12:34
Ai_ling7914-Jan-04 12:34 
GeneralRe: Cross Database insert procedure Pin
Paul Watson14-Jan-04 22:42
sitebuilderPaul Watson14-Jan-04 22:42 
Generalfilter dataset by date Pin
Not Active14-Jan-04 7:22
mentorNot Active14-Jan-04 7:22 
GeneralRe: filter dataset by date Pin
Not Active14-Jan-04 8:55
mentorNot Active14-Jan-04 8:55 
GeneralNot all variables bound. Pin
Chris Meech14-Jan-04 4:58
Chris Meech14-Jan-04 4:58 
GeneralRe: Not all variables bound. Pin
Chris Meech15-Jan-04 9:42
Chris Meech15-Jan-04 9:42 
GeneralRecover SQL database from data file only Pin
TPN12-Jan-04 23:54
TPN12-Jan-04 23:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.