|
-
Sep 17th, 2009, 08:48 AM
#1
Thread Starter
Frenzied Member
Create table via Vb.net to sql
Hallo,
I have the follwoing code which reads a .txt file on my form and shows the path on a textbox called "TextBox1".
Code:
Private Function GetDBName(ByVal filename As String)
Dim MyStreamReader As StreamReader
Dim pathfile As String
pathfile = TextBox1.Text
Try
'Open File
MyStreamReader = File.OpenText(pathfile)
'Read Text
Dim ThisString As String = MyStreamReader.ReadLine
'Close File
MyStreamReader.Close()
MyStreamReader = Nothing
Return ThisString
Catch ex As IOException
Throw New Exception("Unable To Read Text From File", ex)
Finally
MyStreamReader = Nothing
End Try
End Function
The second stage of my development is to have a createtable button. Which when clicked will open the ODBC connection and create a table in a database in SQL.
Please note: The first line of the .txt file is the column names. Therefore the code in VB.net should recognise the column names and save the respective data in each field in SQL server.
The table name can be called "mytable"... I have something below but is with alot of errors can anyone help me pls..
Code:
Private Sub BtnCrtTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCrtTable.Click
' Open the connection
Dim sql As String
Dim cmd As New SqlCommand
Dim conn As SqlConnection = GetDbConnection()
Dim DBName As String = GetDBName(TextBox1.Text)
sql = "CREATE TABLE " & DBName & "
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
' Adding records to the table
sql = "INSERT INTO " & DBName &"
Catch ae As SqlException
MsgBox("Table has been created successfully", MsgBoxStyle.Information, "Load Data Application")
'MessageBox.Show(ae.Message.ToString())
End Try
End Sub
Any help will indeed be highly appreciated.
Thanks
Last edited by dr223; Sep 17th, 2009 at 08:52 AM.
-
Sep 17th, 2009, 09:38 AM
#2
Fanatic Member
Re: Create table via Vb.net to sql
isn't this the third time you've asked this question in three days under three different threads?
-
Sep 17th, 2009, 09:41 AM
#3
Thread Starter
Frenzied Member
Re: Create table via Vb.net to sql
not really.. same functionality but with different approaches neither works though
-
Sep 17th, 2009, 10:32 AM
#4
Re: Create table via Vb.net to sql
How will you determine the data type for each column?
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|