我有一个ASP.NET应用程序和一个MySQL数据库.我想编写一个类来插入,删除和显示数据库中的数据.我有一个数据库连接,但我无法在数据库中插入数据.
我的类插入方法:
public string CreateEntry(string Connectionstring, string mitarbeiter)
{
connection = new MySqlConnection(Connectionstring);
try
{
var command = connection.CreateCommand();
command.CommandText = "INSERT INTO tb_mitarbeiter (Vorname) VALUES ('tom')";
connection.Open();
return "Mitarbeiter wurde angelegt";
}
catch (Exception ex)
{
return ex.Message;
}
finally
{
connection.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
这Connectionstring是对的.我没有收到错误,但数据库中没有数据.
我的tablename:tb_mitarbeiter列:ID和Vorname
我正在尝试使用RGB值而不是我当前的方式设置Excel单元格,因为我需要将单元格设置为特定颜色而不是设置标准颜色.
这就是我目前的做法:
ChartRange.Interior.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbRed;
Run Code Online (Sandbox Code Playgroud)
是否可以在C#中设置RGB值的颜色?
我正在使用在VBA中通过RGB值设置颜色的Excel工作表.
因此,我尝试使用 aButton打开一个CMD.exe窗口来执行一个命令,该命令允许我使用网络中的 IP 自动打开远程桌面。我已经构建了一段代码,但它不起作用。这是代码:
private void cmdRemote_Click(object sender, EventArgs e)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "mstsc /v:" + txtIP.Text;
process.StartInfo = startInfo;
process.Start();
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么它不执行命令。
我开始工作,.net core 并Entityframework 7在Onion Architecture!我阅读了本教程,我认为这是学习以下主题的最佳案例。但是本教程的一部分在我的脑海中提出了一个大问题。就像您在此链接页面上看到的一样;在数据层,我们有一些类是我们的模型!
public class User : BaseEntity
{
public string UserName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public virtual UserProfile UserProfile { get; set; }
}
public class UserProfile : BaseEntity
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public virtual User User { …Run Code Online (Sandbox Code Playgroud) c# onion-architecture entity-framework-core asp.net-core-mvc .net-core
我正在编写正确的代码,但得到错误 - 缺少命名空间或程序集引用.代码有问题或我遗漏了什么?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int i = 0;
int sum = 0;
int[] arr = new int[] { 1, 2 };
do
{
{
sum += arr[1];
Console.WriteLine("Wow");
i++;
}
}
while (i < 3);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:错误无法使用集合初始值设定项初始化类型'int',因为它没有实现'System.Collections.IEnumerable
我的控制台应用程序遇到了一些问题.我想检查用户输入并根据用户写的内容执行某些操作.我的代码看起来像这样:
if(Console.ReadLine() == "ADD")
{
//Add
}
else if (Console.ReadLine() == "LIST")
{
//DisplayList
}
else if (Console.ReadLine() == "SORT")
{
//Sort
}
else
{
//DisplayErrorMsg
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在控制台中键入LIST时,我得到一个换行符,我必须再次键入LIST以获得预期的行为,并且所有后续else-if语句只是添加另一个换行符.(下面的例子)我到处都看,但我看不出我做错了什么......请帮忙!
SORT
SORT
SORT
//Sorting...
Run Code Online (Sandbox Code Playgroud) 我正在使用 Web Api 2 创建 1 个用户。下面是代码
[HttpPost]
public HttpResponseMessage UpdateUserData(User user)
{
try
{
//Code
.
.
user.Update();
return Request.CreateResponse(HttpStatusCode.OK, true);
}
catch (Exception ex)
{
ExceptionLogger.LogException(ex);
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "error");
}
}
Run Code Online (Sandbox Code Playgroud)
我试图从后面的代码中调用这个方法
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:65486/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = client.PostAsJsonAsync("api/Stock/UpdateUserData", userObject).Result;
if (response.IsSuccessStatusCode)
{
using (HttpContent content = response.Content)
{
Task<string> result = content.ReadAsStringAsync();
string final = result.Result;
}
}
else
{
//code
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有几个疑问
我们可以在 HttpResponseMessage …
我有一个应用程序,WinForms其内部列表框我插入名称和价格..名称和价格分别存储在二维数组.现在,当我从中选择一条记录时,listbox只给我一个索引,我可以从中获取字符串名称和价格来更新该记录我必须更改该索引的名称和价格,我想要更新二维数组名称和价钱.但所选索引只是一维的.我想将该索引转换为行和列.怎么做?
但我正在这样的列表框中插入记录.
int row = 6, column = 10;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
value= row+" \t "+ column +" \t "+ name[i, j]+" \t " +price[i, j];
listbox.items.add(value);
}
}
Run Code Online (Sandbox Code Playgroud) 是否有继承具有接口的基类来实现该接口的成员.
一些界面
public interface ICanWork
{
void DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
一些抽象的课
public abstract Class MyBase : ICanWork
{
// I do not want to implement the ICanWork but instead want the derived class which inherit it
}
Run Code Online (Sandbox Code Playgroud)
我继承基类的类
public class House : MyBase
{
// i want the compiler to know that it needs to implement ICanWork
}
Run Code Online (Sandbox Code Playgroud)
这没有像我期望的那样起作用.
通过将接口放在类上继承基类来实现这一目的的唯一方法是什么?
例如
public class House : MyBase, ICanWork
{
}
Run Code Online (Sandbox Code Playgroud)
任何有用的建议?
我正在尝试在C#中进行Parse int,但是我在int mFrom = int.Parse(fromTo.Substring(1, fromTo.IndexOf("C")));下面的行中得到了异常
"System.FormatException:输入字符串的格式不正确.
代码如下:
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
string fromTo= "M5000C001";
int mFrom = int.Parse(fromTo.Substring(1, fromTo.IndexOf("C")));
int cFrom = int.Parse(fromTo.Substring(fromTo.LastIndexOf("C") + 1));
Console.WriteLine("FromTo" + mFrom);
}
}
Run Code Online (Sandbox Code Playgroud)