how to insert a row into database

  • hi...

    i've one table called thoughts

    in that i've two fields

    date and thoughts

    now in front end that is in .aspx page C# code

    there's one textbox and one submit button.

    when i enter text into textbox it should save

    in thought table with the date..

    the date should be in increment order..

    i.e if i enter the data one time today then today's date.

    if i enter the date two times tommorrows date

    if i enter the date three times day after tommorrow's date..

    actually i want to enter the thoughts for one year that is

    365 thoughts and i want to retrive the thought by date..

    Please help me..

  • CREATE TABLE [thoughts]

    (

    id INT IDENTITY(1, 1)

    UNIQUE

    NOT NULL

    , thought VARCHAR(100) NOT NULL

    , th_Date DATETIME2 DEFAULT GETDATE()

    NOT NULL

    ) ;

    INSERT [dbo].[thoughts]

    ( [thought] )

    VALUES ( 'Foobar2' ) ;

    SELECT *

    FROM thoughts ;

    DROP TABLE thoughts

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

    DEFAULT

    Specifies the value provided for the column when a value is not explicitly supplied during an insert. DEFAULT definitions can be applied to any columns except those defined as timestamp, or those with the IDENTITY property. If a default value is specified for a user-defined type column, the type should support an implicit conversion from constant_expression to the user-defined type. DEFAULT definitions are removed when the table is dropped. Only a constant value, such as a character string; a scalar function (either a system, user-defined, or CLR function); or NULL can be used as a default. To maintain compatibility with earlier versions of SQL Server, a constraint name can be assigned to a DEFAULT.

    gsc_dba

  • How about this?

    Table Structure:

    CREATE TABLE [thoughts]

    (

    id INT IDENTITY(1, 1)

    UNIQUE

    NOT NULL

    , DateOfThought DATE

    , thought VARCHAR(500) NOT NULL

    ) ;

    GO

    Stored Procedure:

    CREATE PROCEDURE sp_Add_Thought

    @Thought VARCHAR (500)

    AS

    BEGIN

    DECLARE @LastDate DATETIME

    SELECT @LastDate = MAX(DateOfThought) FROM [thoughts]

    INSERT [dbo].[thoughts] ( DateOfThought , [thought] )

    VALUES ( DATEADD(DD,@LastDate,1), @Thought) ;

    END

  • thanku... it worked..

    one more doubt..

    this is about ssrs reports

    i've one comments field nvarchar(500)DATA TYPE

    in that comment field in every row person name occurs

    like jhon ,smith and steve..

    now what i want is, in that row or textbox is it possible to change

    the color of only for names in textbox .?

    i want like this, it is in a single row

    eg : steve: good morning,jhon : very good morning,steve : whats up

    and is it possible to enter into new line in a textbox ssrs reports for ex : "/n" ?

  • I am a dud in SSRS; Probably if you post in SSRS forums of this same site, you may get a good code. Sorry, i couldn't be of any help to u on this regard.

  • Hey its ok...

    i'll put is ssrs forum...

    once again thanks for replying...

  • vinayak.v (2/21/2011)


    Hey its ok...

    i'll put is ssrs forum...

    once again thanks for replying...

    Pleasure's mine.. Thanks for the feedback, vinayak.

  • vinayak.v (2/21/2011)


    thanku... it worked..

    one more doubt..

    this is about ssrs reports

    i've one comments field nvarchar(500)DATA TYPE

    in that comment field in every row person name occurs

    like jhon ,smith and steve..

    now what i want is, in that row or textbox is it possible to change

    the color of only for names in textbox .?

    i want like this, it is in a single row

    eg : steve: good morning,jhon : very good morning,steve : whats up

    and is it possible to enter into new line in a textbox ssrs reports for ex : "/n" ?

    You might want to lookup "conditional formatting" in SSRS but AFAIK there is no way to apply formatting to a single word within a row of data in a text box - its an all or nothing thing.

    Have you considered capturing the user details separately? That way you could apply conditional formatting on the name field.

    gsc_dba

  • ok i think it is not possible

    to apply to a single word in text box..

    any ways thank u for replying..

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply