我正在尝试将Laravel项目的数据库使用SQL Server。我能够将SQL Server与Laravel 5.2连接。但是,当我尝试将数据植入表中时,出现此错误
[Illuminate\Database\QueryException] SQLSTATE[23000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cann ot insert explicit value for identity column in table 'surveys' when IDENTITY_INSERT is set to OFF. (SQL: insert into [surveys] ([id], [name]) values (10, 'Some Text'))
Run Code Online (Sandbox Code Playgroud)
注意:我正在尝试提供标识值,这可能是导致问题的原因。
在研究SQL错误时,我了解到我需要执行以下查询。
在播种之前,我需要执行
SET IDENTITY_INSERT surveys ON;
Run Code Online (Sandbox Code Playgroud)
播种后,我需要执行
SET IDENTITY_INSERT surveys OFF;
Run Code Online (Sandbox Code Playgroud)
但是我不确定如何使用Laravel执行这些命令
在没有出现此问题的情况下,如何在为身份列提供值时播种?
更新这是我的播种机
<?php
use Illuminate\Database\Seeder;
class FinalSurveyTS extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$myTable = 'surveys';
DB::statement('SET …Run Code Online (Sandbox Code Playgroud) 我有一个正在运行的页面http://some.example.com/myiframes/default.aspx。这个页面有一个 iframe。iframe 源/包含 Laravel 5.2 基础应用程序。
我的 Laravel 页面 URL“这是 iframe 的来源”是https://laravel.example.com。
https://laravel.example.com有一个带有提交按钮的表单。当用户点击它时,他/她会点击同一域上的另一条路线,即https://laravel.example.com/disply/survey
但是每次,我提交表单时都会收到以下异常
TokenMismatchException in VerifyCsrfToken.php line 67:
Run Code Online (Sandbox Code Playgroud)
为了确保我清楚,在页面上http://some.example.com/myiframes/default.aspx我的代码看起来像这样
在我的 laravel 应用程序上,它位于https://laravel.example.com这里是我的表单
<form method="POST" action="https://laravel.example.com/disply/survey" accept-charset="UTF-8" class="form">
<input name="_token" type="hidden" value="Dk6SN4WzO4brbvdnBO6JZ7e1lBGjmYz8GQJ1lYFo">
<input name="survey_id" type="hidden" value="10">
<input name="call_id" type="hidden" value="667">
<input name="pools" type="hidden">
<input name="alt_id_1" type="hidden" value="250">
<input name="alt_id_2" type="hidden" value="5">
<input name="alt_id_3" type="hidden">
<input name="alt_id_4" type="hidden">
<input name="alt_id_5" type="hidden">
<input name="alt_id_6" type="hidden">
<input name="alt_id_7" type="hidden">
<input name="alt_id_8" type="hidden">
<input …Run Code Online (Sandbox Code Playgroud) 我相信SELECTSQL Server 中的每个语句都会导致放置共享锁或密钥锁.但它会在交易中放置相同类型的锁吗?共享锁或密钥锁是否允许其他进程读取相同的记录?
例如,我有以下逻辑
Begin Trans
-- select data that is needed for the next 2 statements
SELECT * FROM table1 where id = 1000; -- Assuming this returns 10, 20, 30
insert data that was read from the first query
INSERT INTO table2 (a,b,c) VALUES(10, 20, 30);
-- update table 3 with data found in the first query
UPDATE table3
SET d = 10,
e = 20,
f = 30;
COMMIT;
Run Code Online (Sandbox Code Playgroud)
此时我的select语句仍会创建共享锁或密钥锁,还是会升级为独占锁?其他事务是否能够从table1读取记录,还是所有事务都会等到我的事务被提交,然后其他事务才能从中进行选择?
在一个应用程序中它是否因为将select语句移到事务之外而只是将插入/更新保留在一个事务中?
我试图检查是否string只包含以下格式的有效数字
123.456
123
.356
Run Code Online (Sandbox Code Playgroud)
但它应该拒绝任何包含非数字的内容,包括双点.以下是一些无效格式
d123.456
123d
12d3
d.1256
12d.456
12.d12
12.d45d
12.45.56
Run Code Online (Sandbox Code Playgroud)
我做了以下事情
SELECT CASE WHEN '123.00' NOT LIKE '%[^0-9.]%' THEN 'Valid' ELSE 'Invalid' END
Run Code Online (Sandbox Code Playgroud)
当除了字符串中有多个点的情况之外似乎有效.
如何调整正则表达式只允许一个点,否则返回'无效'?
我正在尝试创建一个网格来用 3 列(左、中、右)覆盖全屏
这是我的 html 标记
<div class="container-fluid">
<div class="row">
<div class="col-lg-2 d-md-none bg-dark text-white">
<h1>LEFT</h1>
<p>This column should only show up on large views and should be 16.6% of the screen (2/12)</p>
</div>
<div class="col-lg-8 col-md-9 bg-danger text-white">
<h1>MIDDLE</h1>
<p>This column should always show up. it should cover 75% (9/12) of the screen on <= mid-size view. And 66.6% (8/12) …Run Code Online (Sandbox Code Playgroud) 我有一个使用C#Core .NET 2.2框架顶部编写的控制台应用程序.
我正在尝试使用C#库来获取容器中所有目录的列表.据我所知,Azure Blob存储没有真正的目录.相反,它会创建虚拟名称,使blob看起来像Azure Blob Explorer等浏览器中容器内的文件夹
我使用以下代码存储我的文件
CloudBlockBlob blockBlob = container.GetBlockBlobReference("foldername/filename.jpg");
await blockBlob.UploadFromStreamAsync(stream);
Run Code Online (Sandbox Code Playgroud)
所以我想在容器内选择一个不同的前缀名称文件夹名称列表.
所以,如果我有以下blob"foldername1/file1.jpg","foldername1/file2.jpg","foldername1/file3.jpg"和"foldername2/file1.jpg".我想要返回"foldername1","foldername2"
如何从Azure Blob存储中获取不同前缀的列表?
更新
我试图从下面的评论中获得反馈,所以我想出了以下代码
public async Task<string[]> Directories(string path = null)
{
int index = path == null ? 0 : path.Split('/', StringSplitOptions.RemoveEmptyEntries).Length;
BlobContinuationToken token = null;
List<string> directories = new List<string>();
do
{
BlobResultSegment blobsListingResult = await ContainerFactory.Get().ListBlobsSegmentedAsync(path ?? string.Empty, true, BlobListingDetails.None, 5000, token, null, null);
token = blobsListingResult.ContinuationToken;
IEnumerable<IListBlobItem> blobsList = blobsListingResult.Results;
foreach (var item in …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Bootstrap 4.2 Toast。我希望 Toasts 显示在我网站右侧部分的右上角。
我尝试了以下标记,因为它在文档的 boostrap 示例中显示,但我无法让它显示出来。
<!-- Toasts -->
<div aria-live="polite" aria-atomic="true" style="position: relative;">
<!-- Position it -->
<div style="position: absolute; top: 3rem; right: 0;">
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="mr-auto">Toast Title</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="toast-body">
Some Toast Body
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是一个带有我完整标记的小提琴手,但似乎无法显示祝酒词。
我怎样才能显示吐司
我是 C# 和 .NET 的新手。我正在学习 ASP.NET MVC 5。我发现自己花了额外的时间将模型转换为视图模型的一件事。
这是我的模型
public class Overview
{
public string chain_name { get; set; }
public int store_id { get; set; }
public int total_attempts { get; set; }
public int total_unique_number_called { get; set; }
public int total_callable { get; set; }
public int total_completed_interviews { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图模型
public class OverviewViewModel
{
public string chain_name { get; set; }
public int store_id { get; set; }
public int total_attempts { get; …Run Code Online (Sandbox Code Playgroud) 我有一个 ASP.NET MVC 5 基础项目,我在其中使用 css bootstrap 来设计我的页面。
使用 css bootstrap 处理属性。我希望能够覆盖的默认行为errorElement,errorClass,highlight,unhighlight和errorPlacement特性/功能。
这是我尝试过的
首先,我按以下顺序包含了这些包
这是我第一次尝试覆盖包
$.validator.setDefaults({
errorElement: "span",
errorClass: "help-block",
highlight: function (element, errorClass, validClass) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function (element, errorClass, validClass) {
$(element).closest('.form-group').removeClass('has-error');
},
errorPlacement: function (error, element) {
var elm = $(element);
console.log('errorPlacement was called');
if (elm.parent('.input-group').length) {
console.log('parent');
console.log(elm.parent());
error.insertAfter(elm.parent());
}
else if (elm.prop('type') === 'checkbox' || elm.prop('type') === …Run Code Online (Sandbox Code Playgroud) jquery jquery-validate unobtrusive-validation twitter-bootstrap asp.net-mvc-5
使用 c# 是否可以使用关联每个枚举项的属性?
我已使用描述属性为enum项目添加英文描述。
为了给每个项目添加英文描述,我做了以下操作
public enum MyEnum
{
[Description("My First Item")]
First,
[Description("My Second Item")]
Second,
[Description("My Third Item")]
Third
}
Run Code Online (Sandbox Code Playgroud)
enum然后我向我的调用添加了一个扩展方法GetDescription(),它允许我像这样获得描述
public static string GetDescription(this Enum value)
{
Type type = value.GetType();
string name = Enum.GetName(type, value);
if (name != null)
{
FieldInfo field = type.GetField(name);
if (field != null)
{
DescriptionAttribute attr = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attr != null)
{
return attr.Description;
}
}
}
return name;
} …Run Code Online (Sandbox Code Playgroud) c# ×3
sql-server ×3
bootstrap-4 ×2
css ×2
laravel ×2
laravel-5.1 ×2
php ×2
sql ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
azure ×1
enums ×1
html ×1
jquery ×1
laravel-5 ×1
laravel-5.2 ×1
locks ×1
transactions ×1