如何通过文本框输入值保存相同数据的多个时间。

问题描述:

我想多次保存相同的数据,这取决于文本框值。



例外,城市想保存,我们给文本框值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
}