我怎样才能将子串下拉列表 [英] how can I Substring dropdownlist
问题描述
public static Boolean Insert_Imp_Case(int Imp_Case_Id, string Imp_Case_Number, string Imp_Case_Date,
string Case_Ref_No, string Bl_Number, string Bl_Type, string POL, string POD, string PLD, string Client_Coa,
string Case_type)
{
StringBuilder var1 = new StringBuilder();
var1.Append("INSERT INTO Imp_Case_Header \n");
var1.Append(" (Imp_Case_Id, \n");
var1.Append(" Imp_Case_Number, \n");
var1.Append(" Imp_Case_Date, \n");
var1.Append(" Case_Ref_No, \n");
var1.Append(" Bl_Number, \n");
var1.Append(" Bl_Type, \n");
var1.Append(" POL, \n");
var1.Append(" PLD , \n");
var1.Append(" POD , \n");
var1.Append(" Client_Coa, \n");
var1.Append(" Sustring(Case_type,1,1))");
----------------------------------------------------------------------
var1.Append("VALUES ( '" + Imp_Case_Id + "', \n");
var1.Append(" '" + Imp_Case_Number.Replace("'", "''") + "', \n");
var1.Append(" '" + Imp_Case_Date + "', \n");
var1.Append(" '" + Case_Ref_No + "', \n");
var1.Append(" '" + Bl_Number + "', \n");
var1.Append(" '" + Bl_Type + "', \n");
var1.Append(" '" + POL + "', \n");
var1.Append(" '" + PLD + "', \n");
var1.Append(" '" + POD + "', \n");
var1.Append(" '" + Client_Coa + "', \n");
var1.Append(" '" + Case_type + "') ");
Case_Type是下拉列表我想选择第一个字母,然后插入表格,但我没有得到结果。
Case_Type is drop down list I want to pick the first letter and then insert into table but i am not getting the result.
推荐答案
string ctypeChar = string.Empty;
if (Case_type.SelectedItem != null && !string.IsNullOrEmpty(Case_type.SelectedItem.ToString())
cTypeChar = Case_type.SelectedItem.ToString()[0];
然后用cTypeChar替换你追加的Case_type。
但是...
你真的在查询错误,你应该使用参数 [ ^ ]。了解如何使用参数化查询,以便您不要让自己受到SQL注入攻击。
只需仔细阅读,你将Case_type作为字符串传递你可以使用这段代码来计算Case_type值以传递给函数。我编写的代码就好像Case_type是实际的组合框。
Then replace Case_type in your append with cTypeChar.
But...
You are really making your query wrong, you should be using parameters[^]. Read up on how to use parameterized queries so you don't subject yourself to SQL injection attacks.
Just read a little closer, you are passing Case_type as a string into the function. You can use this code to calculate the Case_type value to pass to the function. I wrote the code as if Case_type was the actual combobox.
做这些更改
更改为
Do these changes
change from
var1.Append(" Sustring(Case_type,1,1))");
要
To
var1.Append("Case_type))");
并添加此行
and add this line
Case_type = Case_type.Substring(0, 1);
var1.Append(" '" + Case_type + "') ");
这篇关于我怎样才能将子串下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!