Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C#/MS SQL question...

Options
2»

Comments

  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Still at this, here's where I am with it now, I've tried to put in dropdowna as a variable into the SQL statement like this:

    selectSQL = "SELECT * FROM Vehicle_Data WHERE (Vehicle_Make) = " + dropdowna + "";

    And what is happening now is the query is taking the data within the variable dropdowna and going off to the database and looking for a database column name that equals that data, instead of a field in the Vehicle_Make column that contains the same data as the dropdowna variable, for example, Audi, VW, or whatever the case may be...


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    That SQL statement doesn't look right if you are looking up a string? Need quotes if that is what you meaning to do

    Should be
    select SQL = "SELECT * FROM Vehicle_DATE WHERE (Vehicle_MAKE) = '" + dropdowna+"'";
    

    ?

    Havn't read the thread, nor do I work with C# so apologies if I'm wrong.


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Hallijhua!

    selectSQL = "SELECT * FROM Vehicle_Data WHERE Vehicle_Make = '" + dropdowna + "'";

    The problem all along was where I had the quotes, I got them mixed up!

    Thanks a mil webmonkey...


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    If I could make a suggestion it would be to focus some effort on learning how to read a stack trace. All the information you need to fix these issues is already there.

    Sometimes its as simple as cutting and pasting the error message into Google, although MSDN has everything included too (Google usually takes you to the online version of the MDSN library).


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    As much as I'm beginning to take to this asp.net, I'm starting to seriously question why the good folks at asp.net, can't use simple examples to resolve simple problems....

    All I want to do is post a date and time into my database on an event click...

    No need to convert anything to anything, no need for chopping off the time after the date, nothing sexy, just post a time and a date into a datafield...

    Apparently all I need is:

    DateTime.Now myDateTime1 = new DateTime();

    But do you think I can find an example of this on the web???

    This is why I'm pulling out my hair with asp.net! :rolleyes:

    There is nothing more frustrating when you are trying to pick something up, than seeing answers to complicated or intermediate problems and the very fundamantals being passed by...


  • Advertisement
  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    After a lot of googling and rummaging, I've found the answer:

    DateTime myDateTime1 = new DateTime();
    myDateTime1 = new DateTime();
    myDateTime1 = DateTime.Now;

    At least this does what it says on the tin. I'm starting to think that the reason PHP is easier to pick up is because there are many more down to earth, simple, understandable examples of the application of PHP at entry level on the net... Once you can see results at the simple level, its easy enough to continue on with the more intricate stuff I think...

    If I was going to do the above,

    I'd be instinctively trying something like:

    System.DateTime.Now myDateTime1 = new System.DateTime.now();

    ???


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    If you are doing the insert or update at that instance you could use the GETDATE function in SQL.

    http://msdn.microsoft.com/en-us/library/ms188383.aspx

    Afaik you can only store both date and time but you can do a CONVERT on select statements to format it later.

    It would be less messy. You will have to set the type of field though to DATETIME


  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    Darragh29 wrote: »
    As much as I'm beginning to take to this asp.net, I'm starting to seriously question why the good folks at asp.net, can't use simple examples to resolve simple problems....

    All I want to do is post a date and time into my database on an event click...

    No need to convert anything to anything, no need for chopping off the time after the date, nothing sexy, just post a time and a date into a datafield...

    Apparently all I need is:

    DateTime.Now myDateTime1 = new DateTime();

    But do you think I can find an example of this on the web???

    This is why I'm pulling out my hair with asp.net! :rolleyes:

    There is nothing more frustrating when you are trying to pick something up, than seeing answers to complicated or intermediate problems and the very fundamantals being passed by...

    You declare a DateTime value using:

    DateTime myDT = DateTime.Now;

    This is the standard way of declaring and assigning all variables in .net and I cannot understand how you are struggling to grasp it.

    You can use the out-of-the-box library methods to format this into anything you want by putting a . after myDT and then choosing which option you want from intellisense.


Advertisement