ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: marco.fuhrmann on February 25, 2016, 03:20:02 pm

Title: Connect to Microsoft SQL Database
Post by: marco.fuhrmann on February 25, 2016, 03:20:02 pm
I want to use pqgrid in a c# .net-application.
I didn`t found a way to connect to a MS SQL Database in the Demos (for example Remote Paging). Where I have to configure the connection to the Database(s)?

Normally i use something like this:

Code: [Select]
string source = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\x\x\documents\visual studio 2013\Projects\WebApplication3\WebApplication3\App_Data\Product.mdf;Integrated Security=True";
SqlConnection conn = new SqlConnection(source);
conn.Open();

greetings,
marco.
Title: Re: Connect to Microsoft SQL Database
Post by: paramvir on February 25, 2016, 10:58:44 pm
The connection string can be defined in web.config

Code: [Select]
<configuration>
  <connectionStrings>     
      <add name="pqTestContext" connectionString="data source=localhost;Integrated Security=false;Initial Catalog=x;UID=y;password=z" providerName="System.Data.SqlClient" />
  </connectionStrings>
.....
.....
</configuration>

Entity framework is used for database connectivity.

Code: [Select]
//name of class is same as connection string.
public class pqTestContext : DbContext
{
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<Company> Companies { get; set; }
}

In the remote paging demo, pqTestContext refers implicitly to database connection.

Code: [Select]
  pqTestContext db = new pqTestContext();

and then LINQ is used.

Code: [Select]
var orders = (from order in db.Invoices
                        orderby order.OrderID
                        select order).Skip(skip).Take(pq_rPP);
Title: Re: Connect to Microsoft SQL Database
Post by: marco.fuhrmann on February 26, 2016, 03:14:02 pm
Is there a ParamQuery Grid Tutorial for ASP .NET available (like the php-tutorial) where I can see, how  the "Controller"-class or the "DbContext"-class in the remote paging demo are working?
Normally i use pqgrid only to show the query results from MS SQL or ORACLE-databases. Now I try to use it to edit the the database entries too.
Title: Re: Connect to Microsoft SQL Database
Post by: jenson on March 06, 2017, 08:43:33 am
Hi,

I'm also interested to get a sample on ASP.NET Webform instead of PHP demo/samples.

Thanks.

Regards,
Jenson