Writing value using TextBox and Custom Method

Good afternoon,

I have the following code in my *.razor.cs file to write a value to my database:

       public void WriteTag(string sTagName, string sValue)
    {
        try
        {
            string connectionstring = "Data Source=localhost;Initial Catalog=HMI_DB;User ID=sa;Password=sa;";
            using (SqlConnection con = new SqlConnection(connectionstring))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("", con))
                {
                    //cmd.CommandText = "insert into dbo.CommandQueue values ('" + sTagName + "', '" + sValue + "', 1,'" + DateTime.Now.ToString() + "')";
                    cmd.CommandText = "insert into dbo.CommandQueue values ('" + sTagName + "', '" + sValue + "', 1,'1-2-2021')";
                    //Console.WriteLine(DateTime.Now);
                    cmd.ExecuteNonQuery();
                }
                con.Close();
            }
        }
        catch (Exception ex)
        {
        }
    }
}

Now I have a TextBox in my application that should write a value with the Invoke Method option. But when I use the statement ${InputNewBatchIdChange} I'm getting an error: error CS0428: Cannot convert method group 'InputNewBatchIdChange' to non-delegate type 'object'. Did you intend to invoke the method?

Note that my TextBox has the name InputNewBatchID.

Can you help me further how to write an input value correctly using the TextBox (or another component)?

Thanks in advance!

What is this? According to the error message it is a method and can't be used like this.

According to the name I assume it's the value when you change the value of the TextBox.

image

Appearantly it can't be used as parameter. How do I get the input value to the parameters?

You haven't posted your TextBox declaration and we can't guess what this actually is. Considering its name it is the method generated for the Change event handler but it is a wild guess. I recommend checking the following article which shows how to get the user input in a page property and then use it in a custom method.

Thanks. I looked into it and it's working now!