How to retrieve the records if I have .SQL script file using ADO.net

Discussion in 'ASP .Net Datagrid Control' started by Kiran, Oct 13, 2003.

  1. Kiran

    Kiran Guest

    Hi,
    I need to retrieve records from SQL 2000 datbase using
    ADO.Net
    I have a huge select statement in .sql script file I need
    to run it to get the records How Can I run it and get the
    records

    Can you guide me
    Kiran, Oct 13, 2003
    #1
    1. Advertising

  2. Kiran

    bspann Guest

    Kiran,

    I think what you are wanting to do is create a Stored Procedure in SQL
    Server 2000. Then call the sp using ADO.NET. After ADO.NET gets the data,
    it will be up to you as to how you would like to display the information
    that is returned.

    So the first thing to do is create the stored procedure.

    Brian

    "Kiran" <> wrote in message
    news:059a01c391bf$e64ec990$...
    > Hi,
    > I need to retrieve records from SQL 2000 datbase using
    > ADO.Net
    > I have a huge select statement in .sql script file I need
    > to run it to get the records How Can I run it and get the
    > records
    >
    > Can you guide me
    bspann, Oct 13, 2003
    #2
    1. Advertising

  3. Kiran

    Kiran Guest

    Brian,
    Thanks for the reply.

    I do not have the option to create a stored proc.
    All I have is *.sql script file with a big Select
    statement in it.
    I tried to read the file and pass that sql statement to
    the sqlCommand object but due to the comments in the sql
    file, command object is failing to execute when I call
    command.CommandText = strSql;
    command.CommandTimeout = 0;
    SqlDataReader myReader = command.ExecuteReader();

    but if I copy the contents of the .sql file and run in
    query analyser window it runs.

    I am wondering if I can pass the .sql file name to
    retrieve the recordset object.

    Thanks
    Kiran


    >-----Original Message-----
    >Kiran,
    >
    >I think what you are wanting to do is create a Stored

    Procedure in SQL
    >Server 2000. Then call the sp using ADO.NET. After

    ADO.NET gets the data,
    >it will be up to you as to how you would like to display

    the information
    >that is returned.
    >
    >So the first thing to do is create the stored procedure.
    >
    >Brian
    >
    >"Kiran" <> wrote in message
    >news:059a01c391bf$e64ec990$...
    >> Hi,
    >> I need to retrieve records from SQL 2000 datbase using
    >> ADO.Net
    >> I have a huge select statement in .sql script file I

    need
    >> to run it to get the records How Can I run it and get

    the
    >> records
    >>
    >> Can you guide me

    >
    >
    >.
    >
    Kiran, Oct 13, 2003
    #3
  4. Kiran

    bspann Guest

    I don't understand why you do not have access to create a Stored Procedure
    but you have access to run queries? Creating a view would be better that
    passing SQL from your application to the database engine. Anyway, here is a
    thought.

    You will need to write a method that strips out the comments. Use a
    StringBuilder object to create your SQL statement. This is a better
    resource than appending strings together. Anyway, this should keep you busy
    for a while. :) Also, look at the Regex object. That might come in handy.

    Brian

    "Kiran" <> wrote in message
    news:069f01c391cb$741fde20$...
    > Brian,
    > Thanks for the reply.
    >
    > I do not have the option to create a stored proc.
    > All I have is *.sql script file with a big Select
    > statement in it.
    > I tried to read the file and pass that sql statement to
    > the sqlCommand object but due to the comments in the sql
    > file, command object is failing to execute when I call
    > command.CommandText = strSql;
    > command.CommandTimeout = 0;
    > SqlDataReader myReader = command.ExecuteReader();
    >
    > but if I copy the contents of the .sql file and run in
    > query analyser window it runs.
    >
    > I am wondering if I can pass the .sql file name to
    > retrieve the recordset object.
    >
    > Thanks
    > Kiran
    >
    >
    > >-----Original Message-----
    > >Kiran,
    > >
    > >I think what you are wanting to do is create a Stored

    > Procedure in SQL
    > >Server 2000. Then call the sp using ADO.NET. After

    > ADO.NET gets the data,
    > >it will be up to you as to how you would like to display

    > the information
    > >that is returned.
    > >
    > >So the first thing to do is create the stored procedure.
    > >
    > >Brian
    > >
    > >"Kiran" <> wrote in message
    > >news:059a01c391bf$e64ec990$...
    > >> Hi,
    > >> I need to retrieve records from SQL 2000 datbase using
    > >> ADO.Net
    > >> I have a huge select statement in .sql script file I

    > need
    > >> to run it to get the records How Can I run it and get

    > the
    > >> records
    > >>
    > >> Can you guide me

    > >
    > >
    > >.
    > >
    bspann, Oct 13, 2003
    #4
  5. Kiran

    Kiran Guest

    Hi Brian,
    Other applications generate these script files so we
    do not want to create thousands of stored procedures.
    I tried to strip off the comments in the file and append
    SQL statement in the file using stringBuilder it worked.
    Thanks for your input.

    It would be a Nice to have feature if some ADO oject
    accepts *.sql script file and returns the recordset object.

    Have a great day you Microsoft geeks :)

    Thanks
    Kiran

    >-----Original Message-----
    >I don't understand why you do not have access to create a

    Stored Procedure
    >but you have access to run queries? Creating a view

    would be better that
    >passing SQL from your application to the database

    engine. Anyway, here is a
    >thought.
    >
    >You will need to write a method that strips out the

    comments. Use a
    >StringBuilder object to create your SQL statement. This

    is a better
    >resource than appending strings together. Anyway, this

    should keep you busy
    >for a while. :) Also, look at the Regex object. That

    might come in handy.
    >
    >Brian
    >
    >"Kiran" <> wrote in message
    >news:069f01c391cb$741fde20$...
    >> Brian,
    >> Thanks for the reply.
    >>
    >> I do not have the option to create a stored proc.
    >> All I have is *.sql script file with a big Select
    >> statement in it.
    >> I tried to read the file and pass that sql statement to
    >> the sqlCommand object but due to the comments in the sql
    >> file, command object is failing to execute when I call
    >> command.CommandText = strSql;
    >> command.CommandTimeout = 0;
    >> SqlDataReader myReader = command.ExecuteReader();
    >>
    >> but if I copy the contents of the .sql file and run in
    >> query analyser window it runs.
    >>
    >> I am wondering if I can pass the .sql file name to
    >> retrieve the recordset object.
    >>
    >> Thanks
    >> Kiran
    >>
    >>
    >> >-----Original Message-----
    >> >Kiran,
    >> >
    >> >I think what you are wanting to do is create a Stored

    >> Procedure in SQL
    >> >Server 2000. Then call the sp using ADO.NET. After

    >> ADO.NET gets the data,
    >> >it will be up to you as to how you would like to

    display
    >> the information
    >> >that is returned.
    >> >
    >> >So the first thing to do is create the stored

    procedure.
    >> >
    >> >Brian
    >> >
    >> >"Kiran" <> wrote in message
    >> >news:059a01c391bf$e64ec990$...
    >> >> Hi,
    >> >> I need to retrieve records from SQL 2000 datbase

    using
    >> >> ADO.Net
    >> >> I have a huge select statement in .sql script file I

    >> need
    >> >> to run it to get the records How Can I run it and get

    >> the
    >> >> records
    >> >>
    >> >> Can you guide me
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
    Kiran, Oct 14, 2003
    #5
    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.
Similar Threads
  1. Jacky
    Replies:
    4
    Views:
    2,253
    Ken Cox [Microsoft MVP]
    Oct 27, 2003
  2. nita
    Replies:
    1
    Views:
    857
    Saravana
    Nov 20, 2004
  3. Replies:
    5
    Views:
    482
    Oren Tirosh
    Nov 14, 2005
  4. Mark B
    Replies:
    0
    Views:
    403
    Mark B
    May 7, 2008
  5. LetMeDoIt
    Replies:
    3
    Views:
    188
    Bob Barrows [MVP]
    May 21, 2007
Loading...

Share This Page