小编Sol*_*man的帖子

如何通过C#中的字符串中的名称找到文本框控件?

请考虑以下代码段:

 protected void displayGannt()
        {
            TextBoxT0.BackColor = getColour(time.moments[0]);
            TextBoxT1.BackColor = getColour(time.moments[1]);
            TextBoxT2.BackColor = getColour(time.moments[2]);
            TextBoxT3.BackColor = getColour(time.moments[3]);
            TextBoxT4.BackColor = getColour(time.moments[4]);
            TextBoxT5.BackColor = getColour(time.moments[5]);
            TextBoxT6.BackColor = getColour(time.moments[6]);
Run Code Online (Sandbox Code Playgroud)

是否有任何可想到的方法将这段代码放入带有计数器的for循环中,而不必写出一百万行代码?是否有任何c#宏可以在某种for循环中完成这项工作?我当然不能想办法.感谢您的回答.

c# for-loop

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

'(更新数据库中的记录时)附近的语法不正确

我的代码产生了Incorrect syntax near '('异常.我尝试了两种不同的方法,但它们都产生了相同的异常.我正在尝试更新数据库中的记录.

这是我的代码,产生异常的行是Execute非查询行.在updater.Fill(dtable)这也注释掉产生相同的异常.

protected void btnSave_Click(object sender, EventArgs e)
{
    int found = 0; // No match found so far

    // Get the current selected Manufacturer
    string currentManufacturer = grdManufact.SelectedRow.Cells[1].Text;
    string currentIsModerated = grdManufact.SelectedRow.Cells[3].Text;

    // Connect to the database
    string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
    SqlConnection conn = new SqlConnection(strConnectionString); 
    conn.Open();


    // Try to find if new record would be a duplicate of an existing database record
    if (txtManufactureName.Text != currentManufacturer)
    {
        string findrecord = "SELECT …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server

-3
推荐指数
1
解决办法
1958
查看次数

标签 统计

c# ×2

for-loop ×1

sql ×1

sql-server ×1