在我的.NET Windows应用程序中,我需要每次插入大约1000万个数据.但是,根据我的低效代码,保存到SQL服务器需要5分钟以上.有任何最佳方法可以最大限度地减少保存这些数据所需的时间?
private void saveAllDataInGrid()
{
int rowCount = dataGridView1.RowCount;
String str = "server=DESKTOP-TDV8JQ7;database=ExcelFileApp;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(str);
con.Open();
for (int count = 0; count < rowCount; count++)
{
try
{
String query = "insert into TemMainTable values (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13,@p14,@p15,@p16,@p17,@p18,@p19,@p20,@p21,@p22,@p23)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@p1", dataGridView1.Rows[count].Cells[0].Value.ToString());
cmd.Parameters.AddWithValue("@p2", dataGridView1.Rows[count].Cells[1].Value.ToString());
cmd.Parameters.AddWithValue("@p3", dataGridView1.Rows[count].Cells[2].Value.ToString());
cmd.Parameters.AddWithValue("@p4", dataGridView1.Rows[count].Cells[3].Value.ToString());
cmd.Parameters.AddWithValue("@p5", dataGridView1.Rows[count].Cells[4].Value.ToString());
cmd.Parameters.AddWithValue("@p6", dataGridView1.Rows[count].Cells[5].Value.ToString());
cmd.Parameters.AddWithValue("@p7", dataGridView1.Rows[count].Cells[6].Value.ToString());
cmd.Parameters.AddWithValue("@p8", dataGridView1.Rows[count].Cells[7].Value.ToString());
cmd.Parameters.AddWithValue("@p9", dataGridView1.Rows[count].Cells[8].Value.ToString());
cmd.Parameters.AddWithValue("@p10", dataGridView1.Rows[count].Cells[9].Value.ToString());
cmd.Parameters.AddWithValue("@p11", dataGridView1.Rows[count].Cells[10].Value.ToString());
cmd.Parameters.AddWithValue("@p12", dataGridView1.Rows[count].Cells[10].Value.ToString());
cmd.Parameters.AddWithValue("@p13", dataGridView1.Rows[count].Cells[12].Value.ToString());
cmd.Parameters.AddWithValue("@p14", dataGridView1.Rows[count].Cells[13].Value.ToString());
cmd.Parameters.AddWithValue("@p15", dataGridView1.Rows[count].Cells[14].Value.ToString());
cmd.Parameters.AddWithValue("@p16", dataGridView1.Rows[count].Cells[15].Value.ToString());
cmd.Parameters.AddWithValue("@p17", …Run Code Online (Sandbox Code Playgroud) 我有一个Windows应用程序,它使用FileSystemWatcher来监视文件的更改.可以添加多个文件位置,并为每个位置创建一个新的FileSystemWatcher实例,并将该位置添加到列表框中.可以选择从列表框中删除位置.删除位置时,我需要删除/处理FileSystemWatcher的特定实例.有没有办法达到这个目的?提前致谢.
FileSystemWatcher fsw;
private void CreateFWInstance(string strLoc)
{
if (strLoc != string.Empty)
{
fsw = new FileSystemWatcher();
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Path = strLoc;
fsw.SynchronizingObject = this;
fsw.EnableRaisingEvents = true;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个app.exe应用程序要求输入输入路径字符串,一旦我输入,它会询问输出路径字符串...现在当我输入时,app.exe执行一些操作
我需要从我的窗体应用程序传递这些路径我看到很多这样的问题但是无法实现我需要的东西,因为我从未使用过程和Stream Reader或Writer任何帮助请...示例将被感谢...谢谢您..
string input = @"C:\Documents and Settings\pankaj\Desktop\My File\greetingsfreinds.ppt";
string output = @"C:\Documents and Settings\pankaj\Desktop\test";
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\Wondershare\MyApp\app.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.Start();
process.WaitForExit(3000);
process.Close();
Run Code Online (Sandbox Code Playgroud)
好吧,我试过,但它给了一些例外 StandardOut没有重定向或过程还没有开始 ......我的代码是
string input = @"C:\Documents and Settings\pankaj\Desktop\My File\greetingsfreinds.ppt";
string output = @"C:\Documents and Settings\pankaj\Desktop\test";
Process process = new Process();
process.StartInfo.FileName = @"C:\Program Files\Wondershare\MyApp\app.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.Arguments = input + ";" …Run Code Online (Sandbox Code Playgroud) 我在Windows窗体应用程序的应用程序项目类路径目录中有一个文本文件。现在在安装时,我正在尝试将文本值写入文本文件。这是我的文本文件安装程序类代码。
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConnectionString.txt",param3);
Run Code Online (Sandbox Code Playgroud)
安装后,我想检索在“ ConnectionString.txt”文件中输入的文本,并在应用程序中使用它,但是我没有得到如何检索文本文件中存在的文本值的信息。
我的Windows窗体应用程序中有checkboxlist,我想检查是否至少选中了一个复选框.如果是这样,我的代码将继续执行,如果不是,则应显示错误消息.我该怎么做?
我有一个将短信发送到提供的手机号码的网址。我只想从Windows应用程序中调用此URL,但不要在浏览器中打开。我只想从Windows应用程序执行该URL。
网址示例
http://mycompany.com/sms.aspx?mobilenum=9123444777&Message=this is a test message
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这种方式。但是它正在浏览器中打开。我不希望在浏览器中打开它。我只想在内部执行此行。
System.Diagnostics.ProcessStartInfo sInfo = new
System.Diagnostics.ProcessStartInfo("http://mycompany.com
/sms.aspx?mobilenum=9123444777&Message=this is a test message");
System.Diagnostics.Process.Start(sInfo);
Run Code Online (Sandbox Code Playgroud)
谢谢。
我想比较3组中的数字.
string first = "1.0.1";
string second = "1.0.0";
string third = "2.1.0";
string forth = "1.1.0";
Run Code Online (Sandbox Code Playgroud)
这些都是版本.我希望从中获得最高版本.目前第三名="2.1.0"最高.
谁有人建议我最短路?或者我应该自定义编码?
我们有一个针对Windows 8.1和Windows 10的企业Windows商店应用程序.我们目前正在使用sideloading来部署应用程序.我们需要能够为特定设备上的所有用户部署应用程序.
根据这篇technet文章:
https://technet.microsoft.com/en-us/library/dn613833(v=ws.11).aspx
您可以使用DISM为设备上的所有用户配置应用程序,但仅适用于尚未登录该设备的用户:
配置的应用程序将注入映像中,并在用户首次登录时为每个用户安装.
我想要做的是为特定设备上的所有当前用户安装我们的应用程序,无论他们之前是否已登录该设备.
我做了很多研究,但我没有找到任何有关如何实现这一目标的细节.
目前Windows商店应用程序是否可以使用?
windows-applications windows-store-apps sideloading windows-8.1 dism
我们正在开发一个 Windows 桌面应用程序,它从其他应用程序的其他控件中提取值。我们所拥有的对于大多数桌面应用程序都非常有用。我注意到某些控件没有出现在检查和 Spy++ 中。例如,在 GP 2015 客户端中,只有少数控件可在 Spy++ 和 Inspect 中寻址。大多数不会显示在 Spy++ 或 Inspect 中的相应树中。哪些类型的控件未显示在 Inspect 中?为了获得额外奖励,我们如何与他们交谈?
提前致谢,史蒂夫
在发布这个问题之前,我认为这是一个简单的问题,我搜索答案并没有找到合适的解决方案.
在我的日常工作中,我正在使用Web应用程序,可以轻松获取或设置下拉列表的值
我不能在Windows应用程序C#中做同样的事情
我有组合框和类comboItem
public class ComboItem
{
public int Key { get; set; }
public string Value { get; set; }
public ComboItem(int key, string value)
{
Key = key; Value = value;
}
public override string ToString()
{
return Value;
}
}
Run Code Online (Sandbox Code Playgroud)
假设组合框通过硬编码绑定,值为
关键:2 /价值:女性
关键:3 /价值:未知
假设我有Key = 3并且我想通过代码设置此项(其键为3),因此在加载表单时,默认情况下所选的值将为Unknown.
combobox1.selectedValue =3 //Not Working , selectedValue used to return an object
combobox1.selectedIndex = 2 //Working as 2 is the index of key 3/Unknown
Run Code Online (Sandbox Code Playgroud)
但是让我说我不知道索引,我怎样才能得到key = 3的项目的索引? …
通过以下代码(timer2的间隔为1000)
private void timer1_Tick(object sender, EventArgs e) {
timer7.Enabled=false;
timer8.Enabled=false;
lblTimer_Value_InBuildings.Text="0";
}
private void timer2_Tick(object sender, EventArgs e) {
lblTimer_Value_InBuildings.Text=(int.Parse(lblTimer_Value_InBuildings.Text)+1).ToString();
}
Run Code Online (Sandbox Code Playgroud)
我们不能在for循环中创建延迟
for(int i=1; i<=Max_Step; i++) {
// my code...
// I want delay here:
timer1.Interval=60000;
timer1.Enabled=true;
timer2.Enabled=true;
// Thread.Sleep(60000); // makes no change even if uncommenting
}
Run Code Online (Sandbox Code Playgroud)
我是否取消对该行Thread.Sleep(60000);或不行,我们什么也看不到有改变lblTimer_Value_InBuildings在timer2_Tick.
你能给我一个解决方案(有或没有计时器)?
我编写了简单的代码,由于获得NullReferenceException的原因我不知道,由于某些特殊原因无法正常工作.
这是简单的应用程序
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private string[] IPToCheck;
private List<string> IPRange;
private bool CorrectNetwork = false;
public MainPage()
{
this.InitializeComponent();
var hostnames = NetworkInformation.GetHostNames();
foreach (var hn in hostnames)
{
if (hn.IPInformation != null &&
(hn.IPInformation.NetworkAdapter.IanaInterfaceType == 71
|| hn.IPInformation.NetworkAdapter.IanaInterfaceType == 6))
{
IPToCheck = hn.DisplayName.Split(new char[] { '.' });
if …Run Code Online (Sandbox Code Playgroud) c# ×10
winforms ×2
asp.net ×1
combobox ×1
dism ×1
inputstream ×1
process ×1
sideloading ×1
sleep ×1
sql ×1
sql-server ×1
text-files ×1
timer ×1
winapi ×1
windows-8.1 ×1