2 Replies - 6178 Views - Last Post: 12 June 2012 - 01:22 AM Rate Topic: -----

#1 traceyy  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 11-June 12

C# forms- problem with dates, auto generating ids and if, else

Posted 11 June 2012 - 11:34 PM

Hey everyone!
Okay, So I'll be as short as possible, sorry if I'm violating any rules, this is like my last resort! I'm designing a small application which takes in student details etc,
I'm stuck in the following areas:
(Ps: I'm using c# forms2010 express and sql server 2008)
(pps: all insert coding is done using parameterized quieries, I'd appreciate if replies are in the same! :( )

1. Is there anyway to insert "date" into table without taking it from the user? (Automatically back-end) Like on submit, it takes the system date and inserts it into the table. I tried a few methods, but they aren't working.
2. Also, I have a datagridview option, it works perfectly, except i want it to be visible only to the user: admin pass: password
for eg:
(admin username is pre-stored in the db)

if(username == admin)
{
datagridview.visible = true
}
else
{
//
}



3. If it's not too much to ask for, I need an auto-generated numeric ID(20120001 -20120999) in the table, this value is to be displayed on the textbox and eventually inserted/overwritten in the db, any small code for that?
The only way I can think of is manually insert all and eventually use an update option


please help! :]

Is This A Good Question/Topic? 0
  • +

Replies To: C# forms- problem with dates, auto generating ids and if, else

#2 traceyy  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 11-June 12

Re: C# forms- problem with dates, auto generating ids and if, else

Posted 12 June 2012 - 12:41 AM

So I managed to solve my Auto-Date question(Q1)

Quite simple actually,

command.Parameters.Add("@NowTime", SqlDbType.DateTime);
command.Parameters["@NowTime"].Value = DateTime.UtcNow;

this stores the current date into the database without the end user having to choose/enter.

still stuck with other queries though :(
Was This Post Helpful? 2
  • +
  • -

#3 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

Re: C# forms- problem with dates, auto generating ids and if, else

Posted 12 June 2012 - 01:22 AM

:code:

You could also use the DateTime property for your numeric ID. If you parse the date, including minutes and seconds to an integer, you are left with a long unique number.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1