.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Database Gateways

Posted By: Nagendra     Posted Date: June 23, 2010    Points:2   Category :C#
Hi every one i made a database gateways to access multiple database with Oledb I have made Insert() Select() Delete()

but there is some problem in Update I am giving my Update code and their method of using
but i am not able to decide how user will give fiels ant its value and type send foe updation

public void UpdateData(string DatabaseProvider, string DatabaseName, string TableName,Dictionary<string ,string> DC,string Condition)
{
string kk = null;
int i = 0;
foreach (KeyValuePair<string, string> jj in DC)
{
kk = kk + jj.Key + "=" + jj.Value ;
if (i == DC.Count- 1)
continue;
kk = kk + ",";
i++;
}

string ss = "Use " + DatabaseName + " update " + TableName + " set " + kk + Condition ;
if (ocon.State == ConnectionState.Closed)
{
ocon.Open();
}
ocmd = new OleDbCommand(ss, ocon);

try
{
int aa= ocmd.ExecuteNonQuery();
if (aa >0)
{
MessageBox.Show("Record Successfully Updated");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}

How To use on button click

ConnectionManager cm = new ConnectionManager("SQL");
Dictionary<string,string > DC = new Dictionary<string,string>();
DC.Add("Price", "290");
DC.Add("High", "80000");
string condition = " where Symbol = 'CXD'";
cm.UpdateData("SQL", "info", "TBuyOrder", DC, condition);

but problem is that the dictionary i make it is string type if user input DateTime ,Double,or anyother type then How we Recognize in our function UpdateData()
any one can help me to solve this

Thanks

Responses
Author: Sunil Yadav       [Moderator]      
Posted Date: June 26, 2010     Points: 5   

Hi,

you can make dictionary to accept object value instead of string as shown below.

Dictionary<object, object> DC = new Dictionary<object, object>();
DC.Add(DateTime.Now, "sunillee");
DC.Add("Price", 290);
DC.Add("High", "80000");

string kk = null;
int i = 0;
foreach (KeyValuePair<object, object> jj in DC)
{
kk = kk + jj.Key + "=" + jj.Value;
if (i == DC.Count - 1)
continue;
kk = kk + ",";
i++;
}




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend