我是Visual Studio的新手,所以这可能是一个非常明显的问题,请提前道歉!
我正在尝试建立一个新的DateTime,我注意到,根据我所在的项目,我必须以不同的方式引用它们才能让它们工作.
在第一个项目中,我可以像这样引用它而没有错误:
DateTime theDate = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
但是在我的第二个项目中,如果我输入完全相同的代码,我会收到错误消息:
Error 1 An object reference is required for the non-static field, method, or property 'ProgPractice.DateTime.Now'
Run Code Online (Sandbox Code Playgroud)
为了解决错误,我必须将系统置于DateTime之前,如下所示:
System.DateTime theDate = System.DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么,或者指向一个资源,以便我了解其中的区别?我用Google搜索了它,但我认为我没有使用正确的术语.
谢谢!
- -编辑 - -
我用过System; 在我的文件的顶部.
我将我的第二个项目命名为DateTime.aspx,我认为这导致了冲突.谢谢你的帮助,不会想到的!
我正在尝试将 JSON 输出到 Web 表单中的下拉列表。我已经做到了这一点:
WebClient client = new WebClient();
string getString = client.DownloadString("http://myfeed.com/app_feed.php");
JavaScriptSerializer serializer = new JavaScriptSerializer();
dynamic item = serializer.Deserialize<object>(getString);
string name = item["title"];
return name;
Run Code Online (Sandbox Code Playgroud)
这使提要恢复正常,但在线路上遇到错误:
string name = item["title"];
Run Code Online (Sandbox Code Playgroud)
带回此错误:
附加信息:字典中不存在给定的键。
这是我的提要示例:
{"apps":[{"title":"title1","description":"description1"},
{"title":"title2","description":"description2"},
{"title":"title3","description":"description3"}
Run Code Online (Sandbox Code Playgroud)
所以我以为我在引用第一个标题,我打算遍历它们:
string name = item["title"];
Run Code Online (Sandbox Code Playgroud)
但显然不是!我查看了 Stackoverflow,但找不到可以应用于我自己的代码的答案。
我真的是 AngularJS 的新手,所以这可能真的很明显!
我有一个服务,它会做一些基本的检查,然后返回信息。我在控制器和函数中调用此服务。
当我在控制器中调用它时,它工作正常,没有错误。
当我在函数中调用它时,我得到
angular.js:9101 ReferenceError: systemService 未定义
在有效的控制器中调用服务:
myApp.controller('continueController', ["$scope", "$rootScope", 'systemService', function ($scope, $rootScope, systemService) {
$scope.ContinueAngularMethod = function () {
$rootScope.field = 'payment';
$scope.field = $rootScope.field;
$scope.notApp = '1';
console.log("I don't error in here");
$scope.ss = systemService.checkDropDownValue($scope.payment.type, $scope.notApp);
$rootScope.$apply();
}
}]);
Run Code Online (Sandbox Code Playgroud)
在不起作用的函数中调用服务:
function MyCtrl($scope) {
$scope.changeme = function () {
console.log("Drop down changes ideally do something here....");
//Call to service
$scope.ss = systemService.checkDropDownValue($scope.payment.type, $scope.notApp);
console.log($scope.ss.field);
console.log($scope.ss.notAppJ);
}
Run Code Online (Sandbox Code Playgroud)
这是我的完整代码:
<script type='text/javascript'>
//Angular stuff
var myApp = …Run Code Online (Sandbox Code Playgroud) 我有一个for循环,它从我的C#Web表单中收集数据,并通过存储过程将它找到的每个项目写入数据库.
我遇到的问题是它只写了一次数据库.我已经逐步完成了visual studio中的代码并插入了测试变量来检查所有数据是否存在并且正在被捕获,这就是它.另外,因为第一次我知道它正在工作时存储过程正确执行.
所以我认为问题可能在于我如何在for循环中获得try catch?
或者可能是完全不同的东西 - 我真的可以用一双新鲜的眼睛和有人指出我正确的方向!
protected void log_hd_number()
{
////write results to DB.
SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Integrated Security=True");
SqlCommand cmd = conn.CreateCommand();
SqlDataReader reader;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "insert_requested_hd";
Dictionary<String, String> hdSize = new Dictionary<String, String>();
hdSize.Add("hardDiskSizeData1", hardDiskSizeData1.Text);
hdSize.Add("hardDiskSizeData2", hardDiskSizeData2.Text);
int numberRequested = 2;
for (int i = 1; i <= numberRequested; i++)
{
cmd.Parameters.AddWithValue("@hd_size", hdSize["hardDiskSizeData" + i]);
cmd.Parameters.AddWithValue("@number_requested", numberRequested);
cmd.Parameters.AddWithValue("@vm_id", 15);
try
{
conn.Open();
reader = cmd.ExecuteReader();
reader.Close();
}
catch (Exception exc) …Run Code Online (Sandbox Code Playgroud)