0

Hi,

I have the database of the application i am doing stored in the bin. Now i want to make a new connection how can i do so?

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by de Source
0

Since no database type was specified, I'll make this generic.
Assuming you have an ODBC data source and it is set up in your Odbc Administrator...

using System;
using System.Data.Odbc;

namespace Dani_368900
{
   class Program
   {
      static void Main(string[] args)
      {
         using (OdbcConnection conn = new OdbcConnection("DSN=..."))
         {
            conn.Open();
            string strSQL = "some SQL HERE ... select asdf from T where ...";
            OdbcCommand cmd = new OdbcCommand(strSQL, conn);
            using (OdbcDataReader rdr = cmd.ExecuteReader())
            {
               while (rdr.Read())
               {
                  Console.WriteLine(rdr[0]); // or use rdr["COLUMN_NAME"].ToString();
               }

               rdr.Close();
            }

            conn.Close();
         }
      }
   }
}

Edited by thines01: ...forgot the Open()

0

Since no database type was specified, I'll make this generic.
Assuming you have an ODBC data source and it is set up in your Odbc Administrator...

using System;
using System.Data.Odbc;

namespace Dani_368900
{
   class Program
   {
      static void Main(string[] args)
      {
         using (OdbcConnection conn = new OdbcConnection("DSN=..."))
         {
            conn.Open();
            string strSQL = "some SQL HERE ... select asdf from T where ...";
            OdbcCommand cmd = new OdbcCommand(strSQL, conn);
            using (OdbcDataReader rdr = cmd.ExecuteReader())
            {
               while (rdr.Read())
               {
                  Console.WriteLine(rdr[0]); // or use rdr["COLUMN_NAME"].ToString();
               }

               rdr.Close();
            }

            conn.Close();
         }
      }
   }
}

no i know how to do that.. I want to do the connection where it generates the connection string.

0

which database you have?

I have a database (SQL Server) one and it's extenstion is *.mdf

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.