如何生成随机行数 [英] how generate random number of row

查看:81
本文介绍了如何生成随机行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,让我给出20的值,当我单击按钮时,它将如何在数据库表中生成20个行(例如tbl_employee). Strike>

i have textbox and let i give a value 20 and when i click the button how it will generate 20 number of rows in my database table(e.g. tbl_employee)..please help me.....

推荐答案

我不知道您的意思,但这是我的逻辑
您可以使用for循环
I dont know what you are implying but here is my logic
you could use for loop
for(int i=0; i<20; i++)
{
    string sqlQuery = "INSERT INTO table(blah)";
    sqlQuery += "VALUES (@blah)";
    using (SqlConnection dataConnection = new SqlConnection(connectionString))
    {
        using (SqlCommand dataCommand = dataConnection.CreateCommand())
            {
            dataConnection.Open();
            dataCommand.CommandType = CommandType.Text;
            dataCommand.CommandText = sqlQuery;
            dataCommand.Parameters.Add("@blah", text to insert);
            dataCommand.ExecuteNonQuery();
            dataConnection.Close();
            }
    }
}


这篇关于如何生成随机行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆