有人可以演示如何将字典值保存到MySQL数据库中吗?
public void Update()
{
Dictionary<string,int> t = new Dictionary<string,int>();
for(int i = 0; i < t.Count;i++)
{
//What comes Here?
}
}
答案 0 :(得分:0)
首先修复你的迭代循环,然后由你来决定,例如:
MySqlConnection conDataBase = new MySqlConnection(constring);
conDataBase.Open();
foreach (KeyValuePair<string, string> entry in)
{
string constring = "..........";
string Query = "insert into Tablename values(@par1,@par2)";
MySqlCommand cmd = new MySqlCommand(Query, conDataBase);
cmd.Parameters.AddWithValue( "@par1",entry.Key)
cmd.Parameters.AddWithValue("@par2",entry.Value)
//Execute command
cmd.ExecuteNonQuery();
}