Problem (Inserting records into sql server 2000 using asp.net)

Discussion in 'ASP .Net' started by =?Utf-8?B?UCBvZiBEaHVtcA==?=, Aug 18, 2005.

  1. Hello,
    I'm new to asp.net and ado.net so please reply considering that in mind. I'm
    trying to insert some records which are in a .CSV file but the insert is
    working double time. i have 744 records in .CSV file and I'm getting them in
    the datareader but when I'm inserting it into table they're inserted as 1500.
    So the total record count in the table is 1500.

    Here is the code:

    While myread.Read
    myread.Read()
    sqlcmd.CommandText = "Insert imported (imp) values('" &
    myread.GetValue(5) & "')"
    sqlcmd.Connection = sqlConn
    sqlcmd.ExecuteNonQuery()
    End While

    Also is there no method like in Ado we use Recordset.EOF
    .
    Thank you.
    =?Utf-8?B?UCBvZiBEaHVtcA==?=, Aug 18, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UCBvZiBEaHVtcA==?=

    Clint Hill Guest

    It may help to see how you are populating the myread DataReader?

    Clint Hill
    H3O Software
    http://www.h3osoftware.com


    P of Dhump wrote:
    > Hello,
    > I'm new to asp.net and ado.net so please reply considering that in mind. I'm
    > trying to insert some records which are in a .CSV file but the insert is
    > working double time. i have 744 records in .CSV file and I'm getting them in
    > the datareader but when I'm inserting it into table they're inserted as 1500.
    > So the total record count in the table is 1500.
    >
    > Here is the code:
    >
    > While myread.Read
    > myread.Read()
    > sqlcmd.CommandText = "Insert imported (imp) values('" &
    > myread.GetValue(5) & "')"
    > sqlcmd.Connection = sqlConn
    > sqlcmd.ExecuteNonQuery()
    > End While
    >
    > Also is there no method like in Ado we use Recordset.EOF
    >
    .
    > Thank you.
    >
    >
    Clint Hill, Aug 18, 2005
    #2
    1. Advertising

  3. Thanks.
    Here goes...........:
    Code:
    
    Dim pathname, filename As String
    Dim varvalue()
    pathname = Server.MapPath("import")
    filename = Request.QueryString("id")
    
    Dim ExcelConnection As New OleDbConnection
    Dim ExcelCommand As New OleDbCommand
    Dim ExcelAdapter As New OleDbDataAdapter
    Dim ExcelDataset As New DataSet
    ExcelConnection = New
    OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathname +
    ";Extended Properties=Text;")
    ExcelConnection.Open()
    ExcelCommand = New OleDbCommand("SELECT * FROM " + filename,
    ExcelConnection)
    Dim myread As OleDbDataReader
    ExcelAdapter = New OleDbDataAdapter(ExcelCommand)
    myread = ExcelCommand.ExecuteReader
    
    'If myread.HasRows Then
    Dim sqlConn As SqlConnection
    sqlConn = New SqlConnection("Server=.;database=Nissan; User Id=sa;
    Password=testing")
    Dim sqlcmd As New SqlCommand
    sqlConn.Open()
    
    While myread.Read
    
    
    ---------------------------------
    Prince of Dhump
    State Dhump of Himalaya

    (Life is short make the full use of it)
    =?Utf-8?B?UCBvZiBEaHVtcA==?=, Aug 18, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page