Convert textbox text to integer

前端 未结 5 1557
感情败类
感情败类 2020-12-09 06:28

I need to convert the text in the textbox of my xaml code to an integer value in C#. I am using .NET 4.0 and Visual Studio 2010. Is there a way to do it in xaml tags itself

5条回答
  •  青春惊慌失措
    2020-12-09 07:22

    If your SQL database allows Null values for that field try using int? value like that :

    if (this.txtboxname.Text == "" || this.txtboxname.text == null)
         value = null;
    else
         value = Convert.ToInt32(this.txtboxname.Text);
    

    Take care that Convert.ToInt32 of a null value returns 0 !

    Convert.ToInt32(null) returns 0
    

提交回复
热议问题