我是Visual Studio的新手.我正在创建一个登录表单.
我有这个代码.
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
try
{
using (OdbcConnection connect = new OdbcConnection(connectionString))
{
connect.Open();
OdbcCommand cmd = new OdbcCommand("SELECT username, password FROM receptionist", connect);
OdbcDataReader reader = cmd.ExecuteReader();
if (username_login.Text == username && password_login.Text == password)
{
this.Hide();
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
else
MessageBox.Show("Invalid User", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
connect.Close();
}
}
catch (OdbcException ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Run Code Online (Sandbox Code Playgroud)
但每当我尝试输入用户名和密码时,都会出现一个错误,称为配置系统无法初始化.我只是想知道这是什么问题,我怎么能解决这个问题?
请帮忙.
如何将我的应用程序窗口置于前面?例如,我的应用程序需要注意.
这是我的个人计划.我需要这个功能.
这就是我得到的.但它没有 100%的工作时间.
public void BringToFrontToEnterCaptha()
{
if (InvokeRequired)
{
Invoke(new Action(BringToFrontToEnterCaptha));
}
else
{
this.TopMost = true;
this.Focus();
this.BringToFront();
this.textBox1.Focus();
this.textBox1.Text = string.Empty;
System.Media.SystemSounds.Beep.Play();
}
}
public void BringToBackAfterEnterCaptha()
{
if (InvokeRequired)
{
Invoke(new Action(BringToBackAfterEnterCaptha));
}
else
{
this.TopMost = false;
}
}
Run Code Online (Sandbox Code Playgroud)
我从背景工作者那里打电话给他们.
BringToFrontToEnterCaptha();
while (!ready)
{
Thread.Sleep(100);
}
BringToBackAfterEnterCaptha();
Thread.Sleep(300);
Run Code Online (Sandbox Code Playgroud)
按"接受"按钮后,bool ready设置为true.
我工作得很好,但并不总是.
我有一个静态计时器类,任何网页都会调用它来计算每个页面构建的时间.
我的问题是静态类线程安全吗?在我的示例中,并发用户会导致启动和停止时间出现问题吗?例如,不同的线程覆盖我的开始和停止值.
public static class Timer
{
private static DateTime _startTime;
private static DateTime _stopTime;
/// <summary>
/// Gets the amount of time taken in milliseconds
/// </summary>
/// <returns></returns>
public static decimal Duration()
{
TimeSpan duration = _stopTime - _startTime;
return duration.Milliseconds;
}
public static void Start()
{
_startTime = DateTime.Now;
}
public static void Stop()
{
_stopTime = DateTime.Now;
}
}
Run Code Online (Sandbox Code Playgroud)
这个类应该是非静态类吗?
(这个类将从asp.net主页调用.)
所以我从我的MVC网络应用程序返回详细的400错误响应.设置existingResponse ="PassThrough"有效,但这不是我想要的.我不想公开所有的失败,我只想在我有自定义响应时公开它们.
自动,默认设置,但我故意设置它.但是,文档说必须设置"SetStatus"标志,但我不知道如何做这样的事情.我编写了以下四种控制器方法来测试它,只有BadRequestD工作.其他人设置状态代码和状态就好了,但是正文内容是"错误请求".
public ActionResult BadRequestA()
{
Response.StatusCode = 400;
return Content("weeeeee");
}
public ActionResult BadRequestB()
{
Response.Status = "400 U DUN MESSED UP";
return Content("weeeeee");
}
public ActionResult BadRequestC()
{
Response.Status = "400 U DUN MESSED UP";
Response.StatusCode = 400;
return Content("weeeeee");
}
public ActionResult BadRequestD()
{
Response.StatusCode = 400;
Response.TrySkipIisCustomErrors = true;
return Content("weeeeee");
}
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,需要从文件系统中读取PDF文件,然后将其写出给用户.PDF是183KB,似乎完美无缺.当我使用底部的代码时,浏览器获取一个224KB的文件,我从Acrobat Reader收到一条消息,说文件已损坏且无法修复.
这是我的代码(我也尝试过使用File.ReadAllBytes(),但我得到了相同的东西):
using (FileStream fs = File.OpenRead(path))
{
int length = (int)fs.Length;
byte[] buffer;
using (BinaryReader br = new BinaryReader(fs))
{
buffer = br.ReadBytes(length);
}
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", Path.GetFileName(path)));
Response.ContentType = "application/" + Path.GetExtension(path).Substring(1);
Response.BinaryWrite(buffer);
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我使用CodeDom.Compiler从source.cs文件编译另一个程序,我在编译时嵌入了一些资源(exe和dll文件),使用:
// .... rest of code
if (provider.Supports(GeneratorSupport.Resources))
{
cp.EmbeddedResources.Add("MyFile.exe");
}
if (provider.Supports(GeneratorSupport.Resources))
{
cp.EmbeddedResources.Add("New.dll");
}
// ....rest of code
Run Code Online (Sandbox Code Playgroud)
在编译文件中,我需要将嵌入资源作为字节数组读取.现在我通过使用下面的函数和使用将资源提取到磁盘来实现这一点
File.ReadAllBytes("extractedfile.exe");
File.ReadAllBytes("extracteddll.dll");
Run Code Online (Sandbox Code Playgroud)
我使用此函数将两个文件解压缩到磁盘后执行此操作:
public static void ExtractSaveResource(String filename, String location)
{
// Assembly assembly = Assembly.GetExecutingAssembly();
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
// Stream stream = assembly.GetManifestResourceStream("Installer.Properties.mydll.dll"); // or whatever
// string my_namespace = a.GetName().Name.ToString();
Stream resFilestream = a.GetManifestResourceStream(filename);
if (resFilestream != null)
{
BinaryReader br = new BinaryReader(resFilestream);
FileStream fs = new FileStream(location, FileMode.Create); // say
BinaryWriter bw = new …Run Code Online (Sandbox Code Playgroud) 这是一个SQL数据库的小型演示,可以添加,更新SQL服务器中的删除成员.
单个SQL Server DB中有两个表,一个是"成员",第二个是"概述".
有一个单一的窗体,语言是c#,项目是在Visual Studio 2010中构建的,当然还有SQL Server 2010中的数据库.
Windows窗体具有"重置,插入,更新和删除"按钮.
但正如我在文本框中提到的,您只能看到最后一个条目.我想要实现的功能是在插入人物x的dID后我只能在年份文本框中插入可以说任何前一年和按下搜索通常要填写所有文本框的信息,并且金额文本框应该显示我从dB输入的条目,根据我输入的年份有多少金额或没有任何意味着可能是会员没有支付某一年.
我需要帮助以编程方式实现此逻辑,因此我想请求帮助.
目前的方案如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SQLDatabase
{
public partial class SQLDBDisplay : Form
{
SqlConnection con = new SqlConnection("Data Source=JG-PC\\SQLEXPRESS;Initial Catalog=TEST;Integrated Security=True");
public SQLDBDisplay()
{
InitializeComponent();
}
SqlDataAdapter da;
DataSet ds = new DataSet();
private void btnSearch_Click(object sender, EventArgs e)
{
SqlDataReader reader;
SqlCommand cmd = new SqlCommand();
try …Run Code Online (Sandbox Code Playgroud) 背景:
我在工作中敬酒我的旧硬盘并且正在换新的硬盘.有了它,我将不得不重建我的机器.我的经理在他的借用笔记本电脑上安装了Windows 7,我一直在使用我的机器没有通信.但我遇到了一个问题.
我们有相当多的应用程序使用Microsoft.Office.Interop.Excel参考.我已经得到了过去的一些错误,但迄今为止我一直停留在过去几天的一个(我的机子居然遭遇了硬盘驱动器故障后的第一个重建),并已unnable以找到一个解决.我已经搜索过此错误,但在Windows 7上找不到任何有此问题的人,尽管我尝试过其他Windows Server 2008修复程序无济于事.
如果我无法解决这个问题,我将无法使用Windows 7并且想知道在重建机器之前只需擦除它并重新开始(第三次).
问题:
操作系统:Windows 7企业版
错误消息:HRESULT异常:0x800A03EC
代码:
Private m_xls As Microsoft.Office.Interop.Excel.Application
Private m_wkbk As Microsoft.Office.Interop.Excel.Workbook
Private m_wksht As Microsoft.Office.Interop.Excel.Worksheet
m_xls = New Application
m_xls.Visible = False : m_xls.DisplayAlerts = False
m_wkbk = m_xls.Workbooks.Open(Me.FilePath)
m_wksht = CType(m_wkbk.ActiveSheet, Worksheet)
'...Write some data...'
m_wkbk.SaveAs(Me.FilePath, XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, False, False, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)
Run Code Online (Sandbox Code Playgroud)
错误发生在最后一行.
到目前为止我尝试过的:
我只是想知道是否有其他人遇到过此问题,因为Windows 7是新的.我可以使用Server 2008,但在我告诉我的经理它不起作用之前我想有一些可靠的推理.
谢谢杰夫
现在我使用它来列出注册表中列出的32bit和64的所有应用程序.我已经看到了如何检查应用程序是否安装没有任何运气的其他示例.
string registryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue("DisplayName"));
}
}
registryKey = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
key = Registry.LocalMachine.OpenSubKey(registryKey);
if (key != null)
{
foreach (String a in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(a);
Console.WriteLine(subkey.GetValue("DisplayName"));
}
}
Run Code Online (Sandbox Code Playgroud)
因此,这个片段在控制台窗口中列出了所有内容,我想要做的就是从显示名称列表中找到一个程序标题,看它是否已安装.
我尝试的最后一件事是
if (subkey.Name.Contains("OpenSSL"))
Console.Writeline("OpenSSL Found");
else
Console.Writeline("OpenSSL Not Found");
Run Code Online (Sandbox Code Playgroud)
我试过的任何东西都是假的或假的.有没有人可以告诉我如何从列表中获取一个标题?
请不要发布众所周知的私有静态void IsApplicationInstalled(p_name)函数.它对我来说根本不起作用.
虽然我一直在尝试使用C#在Excel 2007的Microsoft Visual Studio项目中设置Excel页面缩放页面
代码看起来像这样
private void Sheet1_Startup(object sender, System.EventArgs e)
{
PageSetup.FitToPagesWide = 1;
PageSetup.FitToPagesTall = 1;
PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperA4;
}
Run Code Online (Sandbox Code Playgroud)
PaperSise和Orientation的线条运行良好,但我无法将Excel数据拟合到一个页面上.
难道我做错了什么 ?
MSDN没有多大帮助,因为他们还没有这种语言的代码示例.