【问题标题】:How to get feed back message when the input field is empty in Unity SqliteUnity Sqlite中输入字段为空时如何获取反馈消息
【发布时间】:2017-05-22 02:24:15
【问题描述】:

如果输入字段为空字符串,我想获取消息并且

我收到此错误:Assets/Scripts/FunctionInput_Informasi.cs(37,33): error CS0131: The left-hand side must be a variable, a property or an indexer

我的脚本是

public void simpan_informasiData(){

    var sql = "INSERT INTO t_informasi(judul,keterangan,waktu) VALUES (@judul,@keterangan,datetime());";

    using (var cmd = dbCon.CreateCommand()) {
        cmd.CommandText = sql;
        cmd.Parameters.AddWithValue("@judul",field_judul.text);
        cmd.Parameters.AddWithValue("@keterangan",field_keterangan.text);


        if(string.IsNullOrEmpty(field_judul.text)){
            print="You must fill it...!!!";
        } else 
            cmd.ExecuteNonQuery();  
    }   
}

你能帮我吗...?

【问题讨论】:

  • 您在哪一行代码中遇到了该错误?双击编辑器中的错误,它将显示哪一行

标签: c# sqlite unity3d


【解决方案1】:

首先将if 条件块移到using 块之外。这样您就可以防止不必要的内存分配,并且您不会在 cmd 命令中插入空值。

其次,您不能在 unity3D C# 中为 print 赋值。它是一个函数而不是一个变量。做这样的事情

public void simpan_informasiData()
{
    if(string.IsNullOrEmpty(field_judul.text))
    {
        print("You must fill in then field...!!!");
    }
    else
    {
        var sql = "INSERT INTO t_informasi(judul,keterangan,waktu) VALUES (@judul,@keterangan,datetime());";
        using (var cmd = dbCon.CreateCommand())
        {
            cmd.CommandText = sql;
            cmd.Parameters.AddWithValue("@judul",field_judul.text);
            cmd.Parameters.AddWithValue("@keterangan",field_keterangan.text);
            cmd.ExecuteNonQuery();
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2016-12-13
    相关资源
    最近更新 更多