I've done this before but I don't have my laptop with me which has all my old code. In my C# class file, I could build a constructor that would pass in the connectionString as a parameter. But I can't remember how to do this now. Here is what I have:
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;
namespace PowerSchool_Test.App_Code
{
public class Student
{
// Define Variables
protected string mstrdbConnectionString;
protected DataSet mdscustomerDataset;
protected DataRow mdrcustomerDataRow;
protected int mintStudentID;
protected string mstrfirstName;
protected string mstrlastName;
// Constructors
// I need an example of the constructor code here that passes in the connectionstring as a parameter.
// Public Properties
public string DBConnectionString
{
get { return mstrdbConnectionString; }
set { mstrdbConnectionString = value; }
}
public string FirstName
{
get { return mstrfirstName; }
set { mstrfirstName = value; }
}
}
}
So I put a comment in under // Constructor
asking for an example of how to code this. Can anyone help?
Member
90 Points
345 Posts
C# class constructor problem when passing connection string as parameter
Apr 18, 2017 04:03 PM|bh0526|LINK
I've done this before but I don't have my laptop with me which has all my old code. In my C# class file, I could build a constructor that would pass in the connectionString as a parameter. But I can't remember how to do this now. Here is what I have:
So I put a comment in under // Constructor
asking for an example of how to code this. Can anyone help?
All-Star
114593 Points
18503 Posts
MVP
Re: C# class constructor problem when passing connection string as parameter
Apr 18, 2017 05:24 PM|Rion Williams|LINK
Try this:
Member
90 Points
345 Posts
Re: C# class constructor problem when passing connection string as parameter
Apr 18, 2017 05:45 PM|bh0526|LINK
Yes, that was easy enough. I went braindead trying to figure that out.