मैंने बैच ऑपरेशंस के लिए SQL सर्वर 2k8 में तालिका मानित पैरामीटर्स का उपयोग शुरू कर दिया है। मुझे इस सुविधा को बहुत पसंद आया और मुझे लगता है कि यह लंबे इंतजार के बाद आया था।.NET मदद में प्रतिबिंब उपयोगकर्ता परिभाषित टाइपनाम को देखकर एक तालिका मूल्यवान पैरामीटर/SqlMetaData [] ऑब्जेक्ट गतिशील रूप से निर्माण कर सकता है?
हालांकि, .NET कोड से एक टीवीपी पास करने के लिए एसक्यूएलएमटाडेटा [] बनाने और फिर लूप में मान भरने में बहुत अधिक कठिनाई शामिल है।
सिंक्रनाइज़ेशन में अपने .NET कोड में SQL सर्वर और SQLMetaData [] ऑब्जेक्ट्स में उपयोगकर्ता परिभाषित प्रकार को रखने के रखरखाव से कैसे बचते हैं? जब मैं एसक्यूएल में एक प्रकार की परिभाषा बदलता हूं, तो मुझे यह जानने का कोई आसान तरीका नहीं है कि मैंने उस प्रकार का उपयोग बड़े पैमाने पर .NET में किया था।
कर सकते हैं .Net प्रतिबिंब उपयोगकर्ता परिभाषित प्रकार का नाम देकर और SQL arrays प्रदान करके डेटा भरने में SQLMetadata बनाने के लिए प्रोग्रामर को सहेज सकता है।
SqlMetaData[] tvp_TradingAllocationRule = new SqlMetaData[13];
try
{
tvp_TradingAllocationRule[0] = new SqlMetaData("ID", SqlDbType.UniqueIdentifier);
tvp_TradingAllocationRule[1] = new SqlMetaData("Name", SqlDbType.VarChar, 255);
tvp_TradingAllocationRule[2] = new SqlMetaData("Description", SqlDbType.VarChar, -1);
tvp_TradingAllocationRule[3] = new SqlMetaData("Enabled", SqlDbType.Bit);
tvp_TradingAllocationRule[4] = new SqlMetaData("Category", SqlDbType.VarChar, 255);
tvp_TradingAllocationRule[5] = new SqlMetaData("Custom1", SqlDbType.VarChar, 255);
tvp_TradingAllocationRule[6] = new SqlMetaData("Custom2", SqlDbType.VarChar, 255);
tvp_TradingAllocationRule[7] = new SqlMetaData("Custom3", SqlDbType.VarChar, 255);
tvp_TradingAllocationRule[8] = new SqlMetaData("CreatedBy", SqlDbType.VarChar, 20);
tvp_TradingAllocationRule[9] = new SqlMetaData("CreatedTS", SqlDbType.DateTime);
tvp_TradingAllocationRule[10] = new SqlMetaData("ModifiedBy", SqlDbType.VarChar, 20);
tvp_TradingAllocationRule[11] = new SqlMetaData("ModifiedTS", SqlDbType.DateTime);
tvp_TradingAllocationRule[12] = new SqlMetaData("IsFactory", SqlDbType.Bit);
}
catch (Exception ex)
{
throw new Exception("Error Defining the tvp_TradingActionCondition in .Net" + ex.Message);
}
foreach (TradingRuleMetadata ruleMetadata in updatedRules)
{
SqlDataRecord tradingAllocationRule = new SqlDataRecord(tvp_TradingAllocationRule);
try
{
tradingAllocationRule.SetGuid(0, ruleMetadata.ID);
tradingAllocationRule.SetString(1, ruleMetadata.Name);
tradingAllocationRule.SetString(2, ruleMetadata.Description);
tradingAllocationRule.SetBoolean(3, ruleMetadata.Enabled);
tradingAllocationRule.SetString(4, ruleMetadata.Category);
tradingAllocationRule.SetString(5, ruleMetadata.Custom1);
tradingAllocationRule.SetString(6, ruleMetadata.Custom2);
tradingAllocationRule.SetString(7, ruleMetadata.Custom3);
tradingAllocationRule.SetString(8, ruleMetadata.CreatedBy);
tradingAllocationRule.SetDateTime(9, ruleMetadata.CreatedDate);
tradingAllocationRule.SetString(10, ruleMetadata.ModifiedBy);
tradingAllocationRule.SetDateTime(11, ruleMetadata.ModifiedDate);
tradingAllocationRule.SetBoolean(12, ruleMetadata.IsFactory);
tvp_TradingAllocationRuleRecords.Add(tradingAllocationRule);
}
catch (Exception ex)
{
}
}
अब अगर अपनी मेज 100 स्तंभ होते हैं, अपने कोड की कल्पना:
इस उदाहरण पर विचार करें।
मेरा उत्तर हटाया गया, यह बहुत उपयोगी नहीं है। आप .net –
में डायनामिक डेटा प्रकार की जांच करना चाहेंगे, क्या आप वर्तमान में उपयोग किए जा रहे कोड का नमूना दिखा सकते हैं? – svick
@svic: आपके लिए एक नमूना कोड पोस्ट किया गया ... – vinayvasyani