我试图让NLOG写入到数据库,但我目前的代码,它抛出一个异常,当我试图调试,例外情况是:为"NotifyIcon.Program"的类型初始值引发异常.
我的NLog配置文件代码如下,因为这似乎是导致问题,因为它是我改变的唯一代码.
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<target name="database" xsi:type="Database" />
<target xsi:type="Database"
name="String"
dbUserName="Layout"
dbProvider="sqlserver"
useTransactions="false"
connectionStringName="String"
connectionString="Data Source=AC-02\SQLEXPRESS;Initial Catalog=master;Integrated Security=True"
keepConnection="true"
dbDatabase="Layout"
dbPassword="Layout"
dbHost="Layout"
installConnectionString="Layout"
commandText="INSERT INTO Logs (Machine_Name, Username, Logon_Time, Screensaver_On, Screensaver_Off, Logoff_Time, Program_Start) Values @MachineName, @Username, @LogonTime, @Screensaver_On, @Screensaver_Off, @LogoffTime, @ProgramStart "/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="database" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
任何和所有的帮助将不胜感激=]
我正在尝试使用notifyIcon来显示BalloonTip,但是当我按下按钮时它不会显示出来
private void button1_Click(object sender, EventArgs e)
{
OsWatchNotify.Visible = true;
OsWatchNotify.BalloonTipText = "Example";
OsWatchNotify.BalloonTipTitle = "example title";
OsWatchNotify.ShowBalloonTip(1);
}
Run Code Online (Sandbox Code Playgroud)
任何和所有的帮助将不胜感激.
我正在制作一个记录用户活动的程序,我希望能够获得一个Teamviewer ID并将其发送到日志,我知道如何通过将该信息分配给变量来将信息发送到日志中,我不确定如何将teamviewer ID传递给所述变量,并希望得到一些帮助.
任何和所有的帮助将不胜感激:)
嗨,我正在尝试将SQL服务器压缩数据库连接到我的程序,我想要一个删除数据库中所有条目的按钮,当我按下该按钮时程序抛出异常并给出以下错误消息"与网络相关或建立与SQL Server的连接时发生特定于实例的错误.找不到服务器或无法访问服务器.验证实例名称是否正确以及SQL Server是否配置为允许远程连接.(提供程序:SQL网络接口,错误: 26 - 找到指定的服务器/实例时出错""
请帮忙?=]
对不起,代码在下面=]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
namespace Booking_system_Final
{
public partial class PendingJobs : Form
{
SqlConnection sc = new SqlConnection("Data Source=C:\\Users\\Administrator\\My Documents\\BMS_Data.sdf");
public PendingJobs()
{
InitializeComponent();
}
private void PendingJobs_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bMSDataSet.Bookings' table. You can move, or remove it, as needed.
this.bookingsTableAdapter.Fill(this.bMSDataSet.Bookings);
// TODO: …Run Code Online (Sandbox Code Playgroud) 我遇到了一些非常奇怪的东西,我正在利用资源文件在工作项目中进行字符串翻译,目前我有一段代码,它遍历这些资源文件以查找有关问题和解答的本地化版本到FAQ页面,然后遍历它们并在页面上呈现它们.
麻烦的是,我的一个循环工作完美,但另一个只是直接跳到Answer2!
我的代码在下面,我真的无法理解为什么2条代码完全相同会产生不同的结果!
if (LanguageStrings.Culture == null)
{
LanguageStrings.Culture = new CultureInfo("en-gb");
LanguageStrings_FAQ.Culture = new CultureInfo("en-gb");
LanguageStrings_FAQAnswers.Culture = new CultureInfo("en-gb");
}
CultureInfo ResxCulture = new CultureInfo(LanguageStrings.Culture.Name);
List<string> FAQQuestions = new List<string>();
ResourceSet RS = LanguageStrings_FAQ.ResourceManager.GetResourceSet(ResxCulture, true, true);
foreach (DictionaryEntry entry in RS)
{
FAQQuestions.Add(entry.Value.ToString());
}
List<string> FAQAnswers = new List<string>();
ResourceSet RSAnswers = LanguageStrings_FAQAnswers.ResourceManager.GetResourceSet(ResxCulture, true, true);
foreach (DictionaryEntry entry in RSAnswers)
{
FAQAnswers.Add(entry.Value.ToString());
}
Run Code Online (Sandbox Code Playgroud)
RS中的第一项是0,它有一个问题0的键,正如我所期望的那样,但在第二个循环中,索引0是Answers2!
谁能给我一个指针,说明为什么会出现这种情况?
我有一个通用存储库,它采用通用 DbContext 和通用模型,
我拥有的代码只是一个基本的通用存储库,如下所示;
public class DataRepo<T,M> : IDataRepo<T,M> where T:DbContext where M :class
{
private readonly T _Context;
private readonly M _Model;
public DataRepo(T Context, M model)
{
_Context = Context;
_Model = model;
}
public void Delete()
{
_Context.Remove(_Model);
}
public async Task<IEnumerable<T>> GetAll()
{
var results = await _Context.Set<T>().AsQueryable().AsNoTracking().ToListAsync();
return results;
}
public T GetSingleByID(int ID)
{
return _Context.Find<T>(ID);
}
public void InsertBulkItems(ICollection<M> dataModels)
{
_Context.AddRange(dataModels);
}
public void InsertSingleItem()
{
_Context.Add(_Model);
}
public void UpdateItem()
{ …Run Code Online (Sandbox Code Playgroud) 我正在创建一个预订管理系统,我在尝试从SQL数据库中获取数据并插入到我的应用程序的一组文本框中时遇到问题.
我想在DataGridView中显示单击按钮时的客户详细信息,但是当我单击该按钮时,应用程序会抛出异常并显示以下错误消息;
没有数据时无效尝试读取.
我附上了我要查看客户详细信息的屏幕截图,以及按钮的代码,最终会在相应的文本框中显示客户详细信息.任何帮助将不胜感激!
SqlConnection sc = new SqlConnection("Data Source=localhost;Initial Catalog=LoginScreen;Integrated Security=True");
SqlCommand com = new SqlCommand();
com.Connection = sc;
sc.Open();
SqlDataReader read = (null);
com.CommandText = ("select * from Pending_Tasks");
read = com.ExecuteReader();
CustID.Text = (read["Customer_ID"].ToString());
CustName.Text = (read["Customer_Name"].ToString());
Add1.Text = (read["Address_1"].ToString());
Add2.Text = (read["Address_2"].ToString());
PostBox.Text = (read["Postcode"].ToString());
PassBox.Text = (read["Password"].ToString());
DatBox.Text = (read["Data_Important"].ToString());
LanNumb.Text = (read["Landline"].ToString());
MobNumber.Text = (read["Mobile"].ToString());
FaultRep.Text = (read["Fault_Report"].ToString());
sc.Close();
Run Code Online (Sandbox Code Playgroud) 我正在尝试在MVC4,Entity Framework 5.00中启用迁移,但是当我输入命令时会抛出以下错误:
Cannot determine a valid start-up project. Using project 'EFMigrations' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information.
Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file://\\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.5.0.0\tool
s\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At \\s01\data\Documents\Visual Studio 2010\Projects\EFMigrations\packages\EntityFramework.6.0.0-beta1\tools\EntityFramework.psm1:669 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path …Run Code Online (Sandbox Code Playgroud) 我正在尝试将文本框中的值添加到datagridview中,我之前曾问过这个问题,但现在却遇到了另一个错误
INSERT语句中的列多于VALUES子句中指定的值。VALUES子句中的值数必须与INSERT语句中指定的列数匹配。
这是导致错误的代码
private void SaveBtn_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection();
SqlCommand com = new SqlCommand();
sc.ConnectionString = ("Data Source=localhost;Initial Catalog=LoginScreen;Integrated Security=True");
sc.Open();
com.Connection = sc;
com.CommandText = ("INSERT INTO Stock (Prod_ID, Prod_Name, Prod_Cat, Supplier, Cost, Price_1, Price_2, Price_3) VALUES ('"+ProdID.Text+"''"+ProdName.Text+"'+'"+ProdCat.Text+"'+'"+ProdSup.Text+"'+'"+ProdCost.Text+"'+'"+ProdPrice1.Text+"'+'"+ProdPrice2.Text+"'+'"+ProdPrice3.Text+"');");
com.ExecuteNonQuery();
sc.Close();
}
Run Code Online (Sandbox Code Playgroud)
我正在编写一个记录用户空闲时间的程序,但是当我尝试运行该程序时,它会抛出一个Stack Overflow异常.
这些是我的自定义事件
public void OnInactive(EventArgs e)
{
this.OnInactive(new EventArgs());
do
{
var idle2 = GetIdleTime();
GetIdleTime();
System.Diagnostics.Debug.WriteLine(idle2);
}
while (timer.Interval > 5000);
}
public void OnActive(EventArgs e)
{
this.OnActive(new EventArgs());
if (timer.Interval < 5000)
{
var idle3 = GetIdleTime();
System.Diagnostics.Debug.WriteLine(idle3);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经打破了代码,试图找到问题的根源,这似乎在于this.OnInactive(new EventArgs());,但是我很难解决如何解决这个问题,因为我是自定义事件的初学者并且没有编码C#很久了.
对此问题的任何和所有帮助将不胜感激!
在先感谢=]
我在做一个应用程序来记录用户活动和我有一对夫妇的自定义事件的问题,没有异常抛出,没有编译器错误出现,但是当我跑我的应用程序没有写入到控制台,这使我想起了事件根本不开火!我已经告诉事件如果弹出但没有任何反应会显示一条消息,我相信这证实了我的怀疑.
我不是C#或自定义事件的专家,所以任何和所有的帮助将非常感激=]
我的自定义事件的代码如下;
Inactivity inact = new Inactivity();
inact.Active += inactivity_Active;
inact.Inactive += inactivity_Inactive;
public void inactivity_Inactive(object sender, EventArgs e)
{
var logdata1=Inactivity.GetIdleTime();
System.Diagnostics.Debug.WriteLine(logdata1);
MessageBox.Show("Inactive");
}
public void inactivity_Active(object sender, EventArgs e)
{
var logdata2 = Inactivity.GetIdleTime();
System.Diagnostics.Debug.WriteLine(logdata2);
MessageBox.Show("Active");
}
Run Code Online (Sandbox Code Playgroud)
这些是为了引发活动和非活动事件而要调用的方法
public void OnInactive(EventArgs e)
{
EventHandler inactiveEvent = this.Inactive;
if(inactiveEvent!=null)
{
inactiveEvent(this, e);
}
}
public void OnActive(EventArgs e)
{
EventHandler inactiveEvent = this.Inactive;
if (inactiveEvent != null)
{
inactiveEvent(this, e);
}
}
Run Code Online (Sandbox Code Playgroud) c# ×10
sql ×3
events ×2
winforms ×2
ado.net ×1
asp.net-core ×1
asp.net-mvc ×1
collections ×1
database ×1
nlog ×1
sql-server ×1