嗨,如何将多个记录从列表框中插入数据库? [英] hi how to insert multiple records into database from listbox?

查看:43
本文介绍了嗨,如何将多个记录从列表框中插入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好如何从列表框中将多个记录插入数据库?您可以提供用于存储过程的插入过程吗?

hi how to insert multiple records into database from listbox?can u provide insert procedure for storedprocedure??

推荐答案



您可以尝试以下链接 http://www .codeincsharp.blogspot.com/2008/06/how-to-insert-with-progress-bar-c-sharp.html

希望这一点对您有所帮助.

谢谢.
Hi,

You may try this link http://www.codeincsharp.blogspot.com/2008/06/how-to-insert-with-progress-bar-c-sharp.html

I hope this one can help.

Thank You.



假设您的列表框是Employee ListBox,然后将所有emp记录插入数据库,请在Save Button上单击以下方法,单击:

Hi,
suppose your list box is Employee ListBox then to insert all emp records into DB call the following method on Save Button click:

public void SavValues()
    {
        SqlConnection connectionSql = new SqlConnection("Data Source=(local);Integrated Security=sspi");
        SqlCommand commandSql = new SqlCommand();
        commandSql.Connection = connectionSql;
        commandSql.CommandText = "INSERT INTO dbo.Employee (EmployeeName) VALUES (@employeeName)";
        commandSql.Parameters.Add("@employeeName");
        try
        {
            connectionSql.Open();
            for (int indexCounter = 0; indexCounter < listBoxEmployeeName.Items.Count; indexCounter++)
            {
                commandSql.Parameters["employeeName"].Value = listBoxEmployeeName.Items[indexCounter].Text;
                commandSql.ExecuteNonQuery();
            }
            connectionSql.Close();
        }
        catch (Exception exceptionMessage)
        {
            //show error message
        }
        finally
        {
            commandSql.Dispose();
            connectionSql.Close();
            connectionSql.Dispose();
        }
    }


这篇关于嗨,如何将多个记录从列表框中插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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