Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

After creating Table, how to add new Column field name from Checkitems in VB .Net

$
0
0

I want to create table in SQL2012 at run-time. My design form look like -

================================================

|    chklstbox     |                         |           dbo.myTable         |

|-------------------|                         |---------------------------------|

|x  Apple           |                         |myDate Date NOT NULL    |

|x  Banana        |      VB.net         |Apple  varchar(20)           |

|   Cake            |     ======>     |Banana varchar(20)         |

|x  Lime            |                          |Lime   varchar(20)            |

|   Icream         |                          |____________________ |

|____________|

============================================

Dim CmdCreate as String

Dim conn as New SqlConnection("Data Source="My-PC";Initial Catalog=MyDatabase;Integrated Security=True;Pooling=False")

CmdCreate = "CREATE TABLE myLst (myDate Date NOT NULL)"

For Each i As String In chklst.CheckedItems

       CmdCreate = "ALTER TABLE myLst ADD (" & chklst.Items.IndesOf(i) & " varchar(20))"

Next

Dim oCmd AS New SqlCommand(cmdCrate, conn)

oCmd.CommandType = CommandType.Text

oCmd.ExecuteNonQuery()

conn.Close()


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>