none
Alter Table with no data RRS feed

  • Question

  • With this i put a new table in a SQLCE database .

    That works .

     cmd = New SqlCeCommand("ALTER TABLE Datum ADD Specs NVARCHAR(50)", con)
          
            If con.State = ConnectionState.Closed Then con.Open()
            myDA = New SqlCeDataAdapter(cmd)
            myDataSet = New DataSet()
            myDA.Fill(myDataSet, "MyTable")
            MsgBox("Oke")
            If con.State = ConnectionState.Open Then con.Close()

    Everything oke , because i want to save an empty textbox when i want to .

    This i how it looks in the database.

    But i want to put it in the database like this , empty or a space ?

    Is this possible , and so what do i at to this statement.

    cmd = New SqlCeCommand("ALTER TABLE Datum ADD Specs NVARCHAR(50)", con)


    • Edited by KeesBlunder Saturday, November 3, 2018 8:16 PM Change Title
    Saturday, November 3, 2018 8:09 PM

Answers

  • You can also try this:

       ALTER TABLE Datum ADD Specs nvarchar(50) DEFAULT ''

    • Marked as answer by KeesBlunder Saturday, December 1, 2018 2:13 PM
    Saturday, December 1, 2018 2:02 PM

All replies

  • Hello,

    Rather than alter the table, when selecting data do this which keeps the field nullable but mask the null when viewing.

    Select IsNull(Specs, '') As Specs From Datum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, November 3, 2018 10:10 PM
    Moderator
  • Hello Karen,

    Sorry for the late response .

    With this i fill the new Column with a space , works for me. 

    cmd = New SqlCeCommand(" Update Datum SET Specs = ' '", con) 

    Saturday, December 1, 2018 1:40 PM
  • You can also try this:

       ALTER TABLE Datum ADD Specs nvarchar(50) DEFAULT ''

    • Marked as answer by KeesBlunder Saturday, December 1, 2018 2:13 PM
    Saturday, December 1, 2018 2:02 PM
  • Thanks again Viorel_

    Don't have to do the update now , this is in one go.

    Saturday, December 1, 2018 2:13 PM