public static List <XmlCommandItem> ImportCommandFormSP(string connectionString, string database, string spName) { DbParameter[] parameters = GetSpParameters(connectionString, database, spName); string spCode = GetProcedureCode(connectionString, database, spName); XmlCommandItem command = new XmlCommandItem(); command.CommandName = spName; command.CommandText = GetSpCode(spCode); command.Database = database; foreach (DbParameter para in parameters) { XmlCmdParameter myParam = new XmlCmdParameter(); myParam.Name = para.ParameterName; myParam.Type = para.DbType; myParam.Direction = para.Direction; myParam.Size = para.Size; command.Parameters.Add(myParam); } List <XmlCommandItem> list = new List <XmlCommandItem>(1); list.Add(command); return(list); }
/// <summary> /// 将XmlCommand对象中参数数组转换成与指定DbCommand兼容的命令参数数组。 /// </summary> /// <param name="xmlCommand">XmlCommand对象</param> /// <param name="dbCommand">DbCommand对象</param> /// <returns>返回与指定DbCommand兼容的命令参数数组</returns> public static DbParameter[] GetCommandParameters(this XmlCommandItem xmlCommand, DbCommand dbCommand) { if (xmlCommand == null) { throw new ArgumentNullException("xmlCommand"); } if (dbCommand == null) { throw new ArgumentNullException("dbCommand"); } if (xmlCommand.Parameters.Count == 0) { return(new DbParameter[0]); } DbParameter[] array = new DbParameter[xmlCommand.Parameters.Count]; for (int i = 0; i < xmlCommand.Parameters.Count; i++) { XmlCmdParameter p = xmlCommand.Parameters[i]; DbParameter para = dbCommand.CreateParameter(); para.ParameterName = p.Name; para.DbType = p.Type; para.Direction = p.Direction; //if( p.Size != 0 ) para.Size = p.Size; array[i] = para; } return(array); }
internal static int GuessParameterNamePrefixLen(XmlCommandItem xmlCommand) { if (xmlCommand.Parameters.Count == 0) { return(0); } XmlCmdParameter param = xmlCommand.Parameters[0]; int index = 0; for ( ; index < param.Name.Length; index++) { if (Char.IsLetter(param.Name[index])) { break; } } if (index < param.Name.Length) { return(index); } else { return(0); } }
private void SetCommnadToListViewItem(ListViewItem item, XmlCmdParameter parameter) { item.Text = parameter.Name; item.SubItems[1].Text = parameter.Type.ToString(); item.SubItems[2].Text = parameter.Direction.ToString(); item.SubItems[3].Text = parameter.Size.ToString(); item.Tag = parameter; }
private ListViewItem CreateListViewItem(XmlCmdParameter parameter) { ListViewItem item = new ListViewItem(parameter.Name, 0); item.SubItems.Add(parameter.Type.ToString()); item.SubItems.Add(parameter.Direction.ToString()); item.SubItems.Add(parameter.Size.ToString()); item.Tag = parameter; return(item); }
private static XmlCmdParameter ConvertToXmlCmdParameter(Field f) { XmlCmdParameter para = new XmlCmdParameter { Name = "@" + f.Name, Type = f.GetDbType() }; if (para.Type == System.Data.DbType.String && f.Length > 0) { para.Size = f.Length; } return(para); }