如何通过文本框输入值保存相同数据的多个时间。 [英] How to save multiple time of same data by textbox input value.
本文介绍了如何通过文本框输入值保存相同数据的多个时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想多次保存相同的数据,这取决于文本框值。
例外,城市想保存,我们给文本框值3,然后它会在数据库中保存三次。
任何人帮助我,谢谢你。
i want to save same data multiple times which depend on textbox value .
Ex-name ,city want to save, and we give textbox value 3,then it will save three time in database.
anybody help me ,thankyou.
推荐答案
int i;
if (int.TryParse(myTextBox.Text, out i))
{
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
while (i > 0)
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (NameColumn, CityColumn) VALUES (@NM, @CT)", con))
{
cmd.Parameters.AddWithValue("@NM", name);
cmd.Parameters.AddWithValue("@CT", city);
cmd.ExecuteNonQuery();
}
i--;
}
}
}
将给定的文本框值发送到数据库并使用循环进行迭代次数并在循环保持你的插入查询。
send the give textbox value to database and use loop for number of iterations and inside the loop keep your insert query.
试试这个:
Try this:
int totalno;
totalno=Convert.ToInt32(TextBox1.Text);
for (int i = 0; i <= totalno; i++)
{
//insert query
}
这篇关于如何通过文本框输入值保存相同数据的多个时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文