Results 1 to 11 of 11

Thread: import data of excel to sql server

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    62

    Unhappy import data of excel to sql server

    Hello,
    I want a small program which makes it possible to import data of Excel file or txt towards sql server (table) in vb.net 2003 or recupére the data of Excel file towards a datagrid
    thank you in advance

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: import data of excel to sql server

    Well, we aren't going to write it for you but we will help you write if for yourself.

    Do you have anything at all written yet?

  3. #3
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: import data of excel to sql server

    Quote Originally Posted by Hack
    Well, we aren't going to write it for you but we will help you write if for yourself.

    Do you have anything at all written yet?
    like hack say it we are not going to do the program. but we can help you with code.

    now my Opinion. the best way of do that is using the excel file like a database. read and at the same time insert at a sqlserver database.


    The Future Is Always The Way To Live The Life

  4. #4

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    62

    Re: import data of excel to sql server

    Quote Originally Posted by Hack
    Well, we aren't going to write it for you but we will help you write if for yourself.

    Do you have anything at all written yet?

    but I don't know how work with DTS by exmeple I want to then fill the data of fihcier Excel towards DTS how I can do that? and how the data lira data of DTS and to register it on sql server ????

  5. #5

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    62

    Re: import data of excel to sql server

    Quote Originally Posted by gooden
    like hack say it we are not going to do the program. but we can help you with code.

    now my Opinion. the best way of do that is using the excel file like a database. read and at the same time insert at a sqlserver database.
    but how I can read the data of Excel file and store them in a dataset???

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: import data of excel to sql server

    Use an OleDbConnection. It can read the excel file just like it was a table in a database. Google "Excel" and "ConnectionString" and you should get some examples of syntax.

  7. #7
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: import data of excel to sql server

    if you want to put in a sql server you dont need dataset....
    you have here a example

    vb.net Code:
    1. Public SQL As New SqlClient.SqlConnection("server=xxx.xxx.xxx.xxx\SQLEXPRESS;database=database;Uid=user;pwd=pass")
    2.  
    3.     Function GetData() As System.Data.DataSet
    4.  
    5.         Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=c:\file_acess.mdb"
    6.         Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    7.  
    8.         Dim queryString As String = "SELECT * FROM members"
    9.         Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
    10.         dbCommand.CommandText = queryString
    11.         dbCommand.Connection = dbConnection
    12.  
    13.         Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
    14.         dataAdapter.SelectCommand = dbCommand
    15.         Dim dataSet As System.Data.DataSet = New System.Data.DataSet
    16.         dataAdapter.Fill(dataSet)
    17.  
    18.         Return dataSet
    19.     End Function
    20.  
    21.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    22.         SQL.Open()
    23.         Dim dd As DataSet = GetData()
    24.         Dim table As New DataTable
    25.         Dim colum As New DataColumn
    26.         Dim rows As DataRow
    27.         For Each table In dd.Tables
    28.             For Each rows In table.Rows
    29.                 Dim Query1 As String = "INSERT INTO members_sql(username,userpassword) values(@username,@userpassword)"
    30.                 Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(Query1, SQL)
    31.                 cmd.Parameters.AddWithValue("@username", rows("member_login"))
    32.                 cmd.Parameters.AddWithValue("@userpassword", rows("member_password"))
    33.                 Try
    34.                     cmd.ExecuteNonQuery()
    35.                 Catch ex As Exception
    36.                     MessageBox.Show(ex.Message)
    37.                 End Try
    38.             Next
    39.         Next
    40.         SQL.Close()
    41.     End Sub

    hope it helps


    The Future Is Always The Way To Live The Life

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: import data of excel to sql server

    Go to www.ConectionStrings.com all the connection strings you would need can be found there
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: import data of excel to sql server

    Quote Originally Posted by GaryMazzone
    Go to www.ConectionStrings.com all the connection strings you would need can be found there
    that is always the right place to get the strings for connections to many tipes of databases systems


    The Future Is Always The Way To Live The Life

  10. #10

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    62

    Re: import data of excel to sql server

    Quote Originally Posted by Tom Sawyer
    Use an OleDbConnection. It can read the excel file just like it was a table in a database. Google "Excel" and "ConnectionString" and you should get some examples of syntax.
    good I am sorry I included/understood anything and thank you

  11. #11
    Hyperactive Member gooden's Avatar
    Join Date
    Dec 2006
    Location
    Portugal
    Posts
    274

    Re: import data of excel to sql server

    ghizounette see the code i posted. it have all the code. i cant do more then that don't you think?


    The Future Is Always The Way To Live The Life

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width