我是一个全新的n00bie in visual c#,我遇到了一个奇怪的障碍,让我疯狂!这是有问题的代码(是的,Hello World程序):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("Goodbye Cruel World"))
{
textBox1.Text = ("Hello World!");
}
else { textBox1.Text = ("Goodye Cruel World"); }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用textBox1.Text =="再见残酷的世界"; 作为if语句的评估参数在编译器中没有错误(顺便说一句,我使用的是Visual Studio 2012 Ultimate)
程序运行正常.我将文本框文本属性初始化为"Hello World!" 使用VS的设计GUI.我面临的问题是代码仅在用户第一次单击按钮时才起作用.按钮没有任何时候.
我调试了代码,并确保在用户第一次单击按钮时适当更改了文本框文本属性.当用户第二次(或在此之后的任何时间)点击该按钮时,一旦代码到达if语句,它就会跳过它,就好像其中的表达式的评估是FALSE一样.事实上,跟上调试工具,按钮一直只执行else块中的代码,即使我知道我正在使用的TextBox.Text属性之前已经适当更改了.
我在这里失踪了什么?为什么按钮只是在我硬编码的两个字符串之间切换文本框文本值?
我正在尝试编写一个程序,打印出(在字符串变量中)有关mdb数据库的以下信息:
表名称表的总列数
列列表如下:
列名:列数据类型:
为了实现这一点,我使用了两种自定义类型(公共类),当然还有列表.这是我到目前为止的代码(由于这里收集的问题和答案,顺便调整了一小部分):
以下是我创建的用于定义我正在使用的两种新类型的类:
public class ClmnInfo
{
public string strColumnName { get; set; }
public string strColumnType { get; set; }
}
public class TblInfo
{
public string strTableName { get; set; }
public int intColumnsQty { get; set; }
public List<ClmnInfo> ColumnList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是实际获取数据的代码.请记住,我使用OleDB连接到实际数据,一切正常,除了我将在下面描述的问题.作为样品,我目前测试此代码用一个简单的1个表分贝,包含字符串类型的12列1 INT32保存(长整型在Access).
//Here I declare and Initialize all relevant variables and Lists
TblInfo CurrentTableInfo = new TblInfo();
ClmnInfo CurrentColumnInfo = new ClmnInfo();
List<TblInfo> AllTablesInfo = new List<TblInfo>();
//This loop …Run Code Online (Sandbox Code Playgroud)