简体   繁体   English

为什么当我编写ItemListView时会出现错误?

[英]Why when i write ItemListView it gives me error?

I'm working on a job about checking in and out of a school. 我正在做有关办理入学和退学的工作。 And when I write ListViewItem this always gives an error: 当我编写ListViewItem时,总是出现错误:

在此处输入图片说明

Here is my code: 这是我的代码:

SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Alunos WHERE EntradaSaida = 0", conn);
DataTable dt = new DataTable();
da.Fill(dt);

for (int i = 0; i < dt.Rows.Count; i++)
{
    DataRow dr = dt.Rows[i];

    ListViewItem item = new ListViewItem(dr["ID"].ToString());
    item.SubItems.Add(dr["Nome"].ToString());
    item.SubItems.Add(dr["Sobrenome"].ToString());
    item.SubItems.Add(dr["TurmaID"].ToString());
    item.SubItems.Add(dr["Data"].ToString());
    lvEntrada.Items.Add(item);
}
if (lvEntrada.SelectedItems.Count > 0)
{
    conn.Open();

    using (SqlCommand cmd = new SqlCommand("UPDATE Alunos SET ID =@ID EntradaSaida =@Entrada, Data = @Data ", conn))
    {
        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("@Data", DateTime.Now);
        cmd.Parameters.AddWithValue("@Entrada", 1);

        int rows = cmd.ExecuteNonQuery();
    }
}

Add

using System.Windows.Forms;

at the top of your cs file. 在您的cs文件顶部。

Or you know what else.... don't pass in a parameter to your listView... 否则,您知道什么...。不要将参数传递给listView。

ListViewItem item = new ListViewItem();
item.SubItems.Add(dr["ID"].ToString());
item.SubItems.Add(dr["Nome"].ToString());
item.SubItems.Add(dr["Sobrenome"].ToString());
item.SubItems.Add(dr["TurmaID"].ToString());
item.SubItems.Add(dr["Data"].ToString());
lvEntrada.Items.Add(item);

What is lvEntrada ? 什么是lvEntrada does it have a property named Items ? 它有一个名为Items的属性吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当我想通过 C# 运行 GAMS 代码时,visual studio 给我错误? - Why does visual studio gives me error when I want to run the GAMS code via C#? 当我搜索任何记录时,单击“打印”按钮后会出现错误,例如请选择行 - When I search any record then after I click on print button it gives me error such as please select the row 当我指定.cscfg文件时出现错误<Setting name=“serilog:write-to:AzureDocumentDB.endpointUrl” /> - .cscfg file gives error when i specify <Setting name=“serilog:write-to:AzureDocumentDB.endpointUrl” /> 为什么统一给我关于 IEnumerator 的错误 - Why does unity gives me error about IEnumerator 为什么我不能将字符串 person 返回到 main 中? 它给了我一个错误,说字符串“person”不在上下文中,即使我返回了它? - Why can't I return the string person into main? It gives me a error saying that the string "person" is not in the context even though I returned it? 当我尝试玩游戏时,它给了我 CS0023 错误“The ! 运算符不能应用于浮点类型的操作数” - When I try to play the game it gives me the CS0023 error “The ! operator cannot be applied to operand of type float” 我在我的主要 class function 中使用浮动价格和 int categoryDD,但是当我在保存按钮中转换它时,它给了我错误 - I am using float price and int categoryDD in my main class function,but when I convert it in save button it gives me the error 为什么当我在 UI 元素上右键单击 NOT 时编译器会出错 - Why the compiler gives an error when I'm right-clicking NOT on the UI element 为什么当我为Wcf服务键入“ POST”方法时出现“找不到端点”错误? - Why When I Type “POST” Method for Wcf Service It Gives “Endpoint not found” Error? 如果我使用的是Guid Identity Web Api 2,则会给我一个错误 - If I'm using Guid Identity Web Api 2 It gives me an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM