小编Woo*_*ody的帖子

如何删除选定的DataGridViewRow并更新连接的数据库表?

我有一个DataGridViewWindows窗体应用程序的控件(用C#编写).

我需要的是:当用户选择DataGridViewRow,然后单击"删除"按钮时,应该删除该行,接下来,需要使用表适配器更新数据库.

这是我到目前为止:

private void btnDelete_Click(object sender, EventArgs e)
{
    if (this.dataGridView1.SelectedRows.Count > 0)
    {
        dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
    }                
}
Run Code Online (Sandbox Code Playgroud)

此外,这只删除一行.我希望用户可以选择多行.

c# datagridview tableadapter winforms

46
推荐指数
3
解决办法
32万
查看次数

将文件写入Web服务器 - ASP.NET

我只想将TextBox控件的内容写入Web服务器目录根目录中的文件...如何指定它?

请记住,我正在本地测试...它一直在将文件写入我的程序文件\ visual studio\Common\IDE目录而不是我的项目目录(我假设root是Web服务器触发的时候) .

我的问题与在web.config中指定正确的位置有关吗?我试过了,但仍然没有...

非常感谢...

protected void TestSubmit_ServerClick(object sender, EventArgs e)
    {
        StreamWriter _testData = new StreamWriter("data.txt", true);
        _testData.WriteLine(TextBox1.Text); // Write the file.
        _testData.Close(); // Close the instance of StreamWriter.
        _testData.Dispose(); // Dispose from memory.       
    }

c# asp.net file streamwriter

44
推荐指数
4
解决办法
14万
查看次数

使用MS Word中的正则表达式替换文本 - C#

我有一个Word文档,我想打开并用"test"替换社会安全号码的所有实例.

我已经有了打开文档的代码.这是替换的代码.但是,我在这一点上使用正则表达式时遇到了麻烦: _wordApp.Selection.Find.Text =; 在我的代码中.使用正则表达式是一种好方法还是有更好的方法?请记住,我必须匹配任何社会安全号码...因此:\ b [0-9] {3} - [0-9] {2} - [0-9] {4}\b或\ b [0-9] {3} [0-9] {2} [0-9] {4}\b

提前致谢...

object replaceAll = Werd.WdReplace.wdReplaceAll;

_wordApp.Selection.Find.ClearFormatting();
_wordApp.Selection.Find.Text = ;

_wordApp.Selection.Find.Replacement.ClearFormatting();
_wordApp.Selection.Find.Replacement.Text = "test";

_wordApp.Selection.Find.Execute(ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
                ref replaceAll, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
Run Code Online (Sandbox Code Playgroud)

c# regex ms-word

5
推荐指数
1
解决办法
4389
查看次数

使用excel.interop替换excel中的单元格值

我想要扫描excel表,并用零替换任何出现的社会安全号码...我想用Excel.Interop尽可能地这样做,但我现在对任何事情都开放......这里是我的一些代码......过去几个月我在桌子上敲我的头......

 // Get range and convert it to a string variable 
            Excel.Range _range =(Excel.Range)_excelApp.get_Range("A1:K1",Type.Missing);

            // convert the value of our cells in our range
            // to the string variable
            string myString = _range.Cells.Value2.ToString();          

            // match any SSN e.g. 1236780909, 123-33-2445
            if (Regex.IsMatch(myString, @"\b\d{3}\b\d{2}\b\d{4}"));
            {                
                _range.Cells.Value2 = replaceSSN;
            }

            // save our workbook with a new name and create a backup
            _excelWorkbook.SaveAs("Results.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            // close workbook
            _excelWorkbook.Close(false, Type.Missing, Type.Missing);

            // send …

c# regex excel interop replace

2
推荐指数
1
解决办法
2万
查看次数

C#复选框 - 我可以清理它吗?

从form_onload调用此函数.我基本上是在阅读注册表,确定哪些复选框已被勾选,然后在GUI中反映出来.

有没有办法压缩这个并编写更好的代码?如何使用CheckState属性?

谢谢.

伍迪

private void checkExcelSettings()
    {
        // Read what the values are for the checkboxes first and assign them to a string.
        string _excelEnable = Convert.ToString(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Mask Data\", "ExcelEnableHash", "Unchecked"));
        string _excelSSN = Convert.ToString(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Mask Data\", "ExcelSSNHash", "Unchecked"));
        string _excelCC = Convert.ToString(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Mask Data\", "ExcelCCHash", "Unchecked"));
        string _excelWells = Convert.ToString(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Mask Data\", "ExcelWellsHash", "Unchecked"));
        string s=@"t\""; //unimportant no-op to placate stackoverflow syntax highlighter.


        // Now let's make sure we reflect what they are supposed to be in the GUI.
        if (_excelEnable == …
Run Code Online (Sandbox Code Playgroud)

c# checkbox properties

2
推荐指数
2
解决办法
1190
查看次数

数据集不会提交到数据库

我是一个DB编程菜鸟.我需要从文本框字段填充数据库但是当我尝试将其提交到数据库时,我去查看数据库,我看到的只是Nulls ...没有保存...请帮助..

谢谢

private void btnSubmit_Click(object sender, EventArgs e)
    {
        TradesDataSet.TradesRow newTradesRow = tradesDataSet.Trades.NewTradesRow();

        newTradesRow.ID = textBoxTradeID.Text; 
        newTradesRow.EntryPrice = textBoxEntryPrice.Text;
        newTradesRow.ExitPrice = textBoxExitPrice.Text;            

        tradesDataSet.Trades.Rows.Add(newTradesRow);
        tradesDataSet.Trades.AcceptChanges();

        try
        {

            this.Validate();
            this.tradesBindingSource.EndEdit();
            this.tradesTableAdapter.Update(this.tradesDataSet.Trades);                
            MessageBox.Show("Update successful");
        }
        catch (System.Exception ex)
        {
            MessageBox.Show("Update failed");
        }
    }        
Run Code Online (Sandbox Code Playgroud)

c# sql dataset

1
推荐指数
1
解决办法
5293
查看次数