我在C#中有一个类库,它有几个类和一个app.config.我已将ConnectionString放在app.config中,如下所示:
<connectionStrings>
<add name="TRN_DB"
connectionString="Database=TRN;Server=NDTSSN;User ID=ln_users2;Password=%4nu$r!;Connection Timeout=30;pooling=false;"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我尝试在项目的其中一个类中打开连接字符串,如下所示:
string connectionString = ConfigurationManager.ConnectionStrings["TRN_DB"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(connectionString);
con.Open();
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
{"你调用的对象是空的."}
当我在web.config中的web项目中使用相同的方式时,连接字符串是正确的,有人知道如何在app.config中访问它吗?我也是这样用的:
string connectionString = System.Configuration.ConfigurationSettings.AppSettings["TRN_DB"];
Run Code Online (Sandbox Code Playgroud)
这个给我这个错误:
此方法已过时,已被System.Configuration取代!System.Configuration.ConfigurationManager.Appsettings
为了说清楚,我的解决方案中没有任何其他项目,因为我希望我的类库能够独立工作.我无法将web项目和web.config应用于此.所以我应该将连接字符串添加到app.config并访问它或者将web.config添加到我的类库项目中.我不确定哪一个是可行的.
我需要在MVC5中创建一个GridView来查看数据,还需要添加一些下拉列表来过滤数据并在GridView中显示结果.我无法在MVC中找到Grid视图的任何好例子.我应该使用GridView还是只是尝试使用Table?以及如何找到一个关于它的好教程?感谢帮助.
我有一个Application Object,其中包含Applicant对象.申请人对象有雇员对象,其中包含有关就业的所有信息(姓名,地址,......),这可以是0或2,3,4,......我如何获得1个申请的Emp of Count?所以在这种情况下,它必须返回4.但我的代码返回2,因为它返回每个申请人的计数而非申请.
这是我的代码:
public void InsertApplication(Application application)
{
if (application.Applicants != null)
{
foreach (var item in application.Applicants)
{
if (item.Employments != null)
{
application.NumberOfEmployments = item.Employments.Count();
}
}
}
creditApplicationsContext.Applications.Add(application);
}
Run Code Online (Sandbox Code Playgroud)
这是应用程序对象:
public class Application
{
public int Id { get; set; }
public virtual ICollection<Applicant.Applicant> Applicants { get; set; }
public int? NumberOfEmployments { get; set; }
Run Code Online (Sandbox Code Playgroud)
这是申请人的对象:
public class Applicant
{
public int Id { get; set; }
public virtual ICollection<Employment> Employments { get; set; …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下代码将 XML 文件上传到 Azure FTP 服务器:
https://www.c-sharpcorner.com/article/upload-and-download-files-from-blob-storage-using-c-sharp/
我很难找到storageAccount_connectionString?我可以访问 Azure 门户中的服务器,但找不到此连接字符串。
//Copy the storage account connection string from Azure portal
storageAccount_connectionString = "your Azure storage account connection string here";
Run Code Online (Sandbox Code Playgroud) 我尝试这个语句来检查SSN是否为空,返回SSNstr中的值,否则返回null.但是Object reference not set to an instance of an object.当SSN为空时,这会给我带来错误.
Model.DocumentData dt = new Model.DocumentData();
dt.SSNstr = (dt.SSNstr == null ? null :(string)individual.XPathSelectElement("Individual/SSN")).Insert(5,"-").Insert(3,"-");
Run Code Online (Sandbox Code Playgroud)
这是dt类:
[DataMember]
public string SSNstr = string.Empty;
Run Code Online (Sandbox Code Playgroud)
请注意这里我知道如何检查空值但我喜欢在同一行代码中执行.由于我有这么多字段,我需要检查我更喜欢检查代码的1行或更改dt类中的一些事情来处理它.
我在C#中有一个使用Entity Framework 6 for Database部分的方法.这种方法将全年回归.我想知道如何将方法转换为异步方法.
public override IEnumerable<Year> GetYears()
{
return creditApplicationsContext.Years.ToList();
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
如何在"编辑"中禁用"下拉",但在"创建用户"中启用.我在MVC视图中下拉,在jquery中创建和编辑用户.我已经尝试过这些,但没有在jquery中使用以下任何一个禁用它:
$("#dropdown").prop("disabled", false);
$('#dropDownId').attr('disabled', true);
$('#dropdown').prop('disabled', true);
Run Code Online (Sandbox Code Playgroud)
当我喜欢这个时,在我的MVC中:
<select id="organization" class="create-user-select-half" disabled>
Run Code Online (Sandbox Code Playgroud)
它使它禁用但我不能再次在jquery中启用它.
我根据多种条件下三元运算符中的值显示不同的数据:
我有这个,
[attr.data-pendo]="linkedItemType === LinkedItemType.Prospect ? 'pendo-prospects' : 'pendo-loans'"
Run Code Online (Sandbox Code Playgroud)
我还需要添加 1 个条件,
所以它就像:
if linkedItemType === LinkedItemType.Prospect then 'pendo-prospects'
if linkedItemType === LinkedItemType.Loan then 'pendo-loan'
else 'pendo-task'
Run Code Online (Sandbox Code Playgroud)
如何在三元中实现这个?