我想根据 SQLDataReader 读取的输出输出一个字符串(或者可能是其他变量类型,如果字符串不理想)。我一直在玩“while”循环, while (reader.Read())
我需要得到一些可以用 json.net 序列化的东西。
这是我当前的代码 - 它输出到调试日志只是为了确保我成功地从数据库读取。
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "Data Source =.\\SQLEXPRESS; Initial Catalog = TeamProject; Integrated Security = True; MultipleActiveResultSets = True";
string querystring = "RosterMake";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(querystring, connection);
command.CommandType = CommandType.StoredProcedure;
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
System.Diagnostics.Debug.WriteLine("\t{0}\t{1}\t{2}",
reader[0], reader[1], reader[2]);
// What do I put here to make the results something …Run Code Online (Sandbox Code Playgroud) 我正在使用带有MySQL的asp.net mvc开发一个网站,我需要为用户更新网站中的一些信息创建一个简单的限制区域.所以,我在mvc应用程序中创建了一个名为"Admin"的区域,我知道如何使用Forms身份验证和Autorize属性来保护它!它工作正常,但在我的区域的每个控制器中,我必须设置Autorize属性以保护它们.有没有办法保护Web.config中的所有区域?我怎样才能做到这一点?
谢谢
干杯
security asp.net-mvc forms-authentication roles asp.net-mvc-areas
我有以下字符串与SQL命令:
string sql = "select [x] from table where field = [y] order by [w], [z]";
Run Code Online (Sandbox Code Playgroud)
我想获取[brackets](x,y,w,z等)中的键,我怎么能用C#做到这一点?有没有办法用正则表达式(没必要)?
我尝试用while声明做一些事情,但它不起作用.
谢谢
我有一个Web应用程序,我在其中使用List集合.我想用另一个更高效的替换这个片段.
List<Project> liste = notre_admin.Get_Project_List();
Project p = new Project();
foreach (Project pi in liste)
{
if (pi.Id_project == id_project) {p = pi; break;}
}
Run Code Online (Sandbox Code Playgroud)
我想用一行替换这些代码行,其中我使用的find方法List.
如何更改代码段?
我需要一点帮助将分割数组排序为从最高到最低,同时将名称保持在分数旁边.我有点不确定如何这样做,因为阵列是分裂的.此外,有没有办法让用户输入任意数量的名称和分数,而程序没有给用户一个错误?所以如果他们只想输入4个名字和分数,他们所要做的就是按回车键吗?
这是我到目前为止的代码.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace proj09LEA
{
class Program
{
static void Main(string[] args)
{
// declare and array of integers
string[] name = new string[5];
int[] score = new int[5];
Console.WriteLine("\nSaturday Coder's Bowling Team");
Console.WriteLine("Enter in a name and score for each person on the team.");
Console.WriteLine("For example, Mary 143. Just hit Enter when you are done.\n");
// fill an array with user input
for (int i = 0; i < …Run Code Online (Sandbox Code Playgroud) 我试图通过让用户选择他们想要的报告的复选框来动态设置 StudentId。当他们单击 ActionLink 时,我使用 jQuery 在隐藏字段中设置 id 的值。我需要操作链接来读取隐藏字段中的 id。
这些值在隐藏字段中设置,但它们没有从 actionLink 传递到控制器。
我需要将 ReportIds 传递给控制器。
@Html.ActionLink("PrintMed", "GetMedEdVerificationReport", "Student", new { studentIdList = Model.ReportIds }, new { @class = "button print_selected print_selectedMedEd disabled" })
@Html.HiddenFor(model => model.ReportIds)
Run Code Online (Sandbox Code Playgroud)
javascript
$('.print_selectedMedEd').bind('click', function () {
var ids = getPrintIds();
if (ids.length == 0) {
return false;
}
$('#ReportIds').val(ids.toString());
return true;
});
Run Code Online (Sandbox Code Playgroud) 如何使用 C# 从另一个包含旧 string[] 数组子部分的 string[] 创建一个新 string[]?
例如,如果我有:
string[] a = { "cat", "dog", "hamster", "parrot" }
Run Code Online (Sandbox Code Playgroud)
我想在我应该得到的第一个元素之后得到一切:
string[] b = { "dog", "hamster", "parrot" }
Run Code Online (Sandbox Code Playgroud)
如果没有 for 循环这甚至是可能的,我如何实现这一点?
我很擅长使用C#和ASP.NET,我很好奇是否有一个约定在SQL数据库上运行多个查询时命名SqlCommands.例如,我创建了我的SqlConnection,我希望调用一个函数,两个存储过程,并创建一个常规的简单查询.目前,我正在使用:
SqlCommand function = new SqlCommand();
SqlCommand command = new SqlCommand();
SqlCommand proc1 = new SqlCommand();
SqlCommand proc2 = new SqlCommand();
Run Code Online (Sandbox Code Playgroud)
对于这些不同的命令是否有更多的接受命名约定,或者我应该使用单个命令,因为我在后面的代码块中使用CommandText和CommandType调用?
我有一个带有复选框的表,这些复选框会根据用户使用 jquery 的选择自动选中和禁用。但是,当我提交表单时,选中的框值不会发送到模型。如果我删除 jquery 代码并手动选中复选框,那么数据将正确发送到模型并且一切正常。这是我一直在使用的 jquery 代码。我也尝试过使用
$('.verification5').attr('checked', 'checked');
$('.verification5').attr('disabled', 'disabled');
.prop('checked', true);
Run Code Online (Sandbox Code Playgroud) 我一直在从一个线程跳到另一个线程,但似乎找不到我需要的答案。
我想使用 .NET 在单个 ExecuteNonQuery 函数中执行非 SELECT MySQL 语句。
这是我想要运行的一组示例 SQL 语句:
DROP procedure IF EXISTS `SubProcA`;
DROP procedure IF EXISTS `SubProcB`;
DROP procedure IF EXISTS `SubProcC`;
CREATE PROCEDURE 'SubProcD'()
BEGIN
SELECT
(<Subselect Statement>) AS A
,(<Subselect Statement>) AS B
,(<Subselect Statement>) AS C;
END;
CREATE PROCEDURE 'SubProcE'(
VarA TEXT,
VarB VARCHAR(255),
VarC VARCHAR(255),
VarD tinyint(1)
)
BEGIN
SET @Query = "";
SET @Query = <Select Statement>;
PREPARE Statement FROM @Query;
EXECUTE Statement;
DEALLOCATE PREPARE Statement;
END;
Run Code Online (Sandbox Code Playgroud)
如您所见,其中有五个语句(3 个 DROP …
c# ×9
.net ×6
asp.net ×3
asp.net-mvc ×3
ado.net ×2
arrays ×2
collections ×2
sql ×2
asp.net-core ×1
coding-style ×1
html ×1
javascript ×1
jquery ×1
json ×1
linq ×1
mysql ×1
razor ×1
regex ×1
roles ×1
security ×1
sorting ×1
string ×1