我将如何格式化下面的内容?@IsCloneOf的值取决于源记录是否已经从“原始”记录中克隆出来,而“原始”记录可以由txt_IsCloneOf字段是否为空来确定。
cmd.Parameters.AddWithValue("@IsCloneOf", (If txt_IsCloneOf is null then txt_QuestionID.Text else txt_IsCloneOf.Text end if);这用于向SQL存储过程发送值。
发布于 2016-06-08 18:50:39
有多种方法可以做到这一点,这取决于首选的编码风格。
cmd.Parameters.AddWithValue("@IsCloneOf", (txt_IsCloneOf == null) ? txt_QuestionID.Text : txt_IsCloneOf.Text);或
if (txt_IsCloneOf == null)
cmd.Parameters.AddWithValue("@IsCloneOf", txt_QuestionID.Text);
else
cmd.Parameters.AddWithValue("@IsCloneOf", txt_IsCloneOf.Text);或
string isCloneOf = "";
if (txt_IsCloneOf == null)
isCloneOf = txt_QuestionID.Text;
else
isCloneOf = txt_IsCloneOf.Text;
cmd.Parameters.AddWithValue("@IsCloneOf", isCloneOf);发布于 2016-06-08 18:47:39
假设这是带有标记的C#。
cmd.Parameters.AddWithValue("@IsCloneOf", txt_IsCloneOf == null?txt_QuestionID.Text:txt_IsCloneOf.Text;发布于 2016-06-08 18:48:03
txt_IsCloneOf == null ? txt_QuestionID.Text : txt_IsCloneOf.Texthttps://stackoverflow.com/questions/37710504
复制相似问题