Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
any type of help will be apricated
Posted

1 solution

By using given code you can easily create new table in a Database and fill records on that table. You can use this code on the Page_Load or in any Button click event.



Try

If Not (conn.State = ConnectionState.Open) Then

conn.Open()

End If


Dim sql As String = "CREATE TABLE mySchoolRecord" + "
(StudentId INTEGER CONSTRAINT PkeyMyId PRIMARY KEY,"
+ "Name CHAR(50), Address CHAR(255), Contact INTEGER)"

cmd = New OdbcCommand(sql, conn)

cmd.ExecuteNonQuery()



sql = "INSERT INTO mySchoolRecord (StudentId, Name,

Address,Contact) " + "VALUES (1, 'Mr. Manish', "

+ " 'Sector-12,Noida', 2447658 ) "

cmd = New OdbcCommand(sql, conn)

cmd.ExecuteNonQuery()



sql = "INSERT INTO mySchoolRecord (StudentId, Name,

Address,Contact) " + "VALUES (2, 'Mr. Anand', " + " 'Mayur

Vihar,
New Delhi', 2457896) "

cmd = New OdbcCommand(sql, conn)

cmd.ExecuteNonQuery()



sql = "INSERT INTO mySchoolRecord (StudentId, Name,

Address,Contact) " + "VALUES (3, 'Miss Mona', " + "

'25,
Church Road,Mumbai', 2784521) "

cmd = New OdbcCommand(sql, conn)

cmd.ExecuteNonQuery()



If conn.State = ConnectionState.Open Then

conn.Close()

End If


Catch ex As OdbcException


MessageBox.Show(ex.Message.ToString)


End
Try
 
Share this answer
 
Comments
sanit rana 27-Feb-12 1:29am    
i don't know exact number of columns that is decieded on run time

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900