0
我试图制作一个实用程序来生成SQL表的Insert脚本以及关系表。从字符串中删除一个不断变化的值
我得到了c#中的所有值。
现在我想从script.most中删除一个列名及其值,可能是标识列。例如:
例如。
字符串我有(而保持与表的名称改变和变化)
INSERT Core.Customers
([customerId],[customername],[customeradress],[ordernumber])
Values(123,N'Rahul',N'244 LIZ MORN',2334)
现在我知道我必须删除客户ID。 (有时需要用@some变量替换)
请给我一个有效的方法来检索customerId值和删除列名和值。
我正在寻找一种方法来按列名查找coloumn值。
我在做什么是:我知道它效率低下,可能会导致问题,但现在它工作顺利。
public string GetColumnValueToForDesiredColumnName(string row, TableInfo tableinfo, string NameofColumnTOfindvalueFor)
{
Dictionary<string, string> ValueTypedictionary = new Dictionary<string, string>();
string value = null;
// This Code is Quite messy Need some suggestion on this one
string[] plusseperatedinsert = row.Replace("INSERT " + "[" + tableinfo.Schema + "].[" + tableinfo.TableName + "]", string.Empty).Trim().Replace("VALUES", "+").Split('+');
string[] coulumnvalues = plusseperatedinsert[0].Replace("(", string.Empty).Replace(")", string.Empty).Replace("(", string.Empty).Replace("[", string.Empty).Replace("]", string.Empty).Trim().Split(',');
string[] valuesfield = plusseperatedinsert[1].Replace("(", string.Empty).Replace(")", string.Empty).Replace("(", string.Empty).Replace("[", string.Empty).Replace("]", string.Empty).Trim().Split(',');
for (int index = 0; index < coulumnvalues.Length; index++)
{
ValueTypedictionary.Add(coulumnvalues[index], valuesfield[index]);
}
ValueTypedictionary.TryGetValue(NameofColumnTOfindvalueFor, out value);
return value;
}
this gives 123 as value .
and then I am using string.Replace("[customerId],",string.empty).Replace(123,string.empty);