在sql数据库中保存批量值 [英] save bulk value in sql database

查看:95
本文介绍了在sql数据库中保存批量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在sql数据库中同时保存5个客户详细信息(姓名,联系人号码,电子邮件ID,平底锅号码,座机号码,公司名称,名称等)。

哪个控件我应该使用

我可以使用''datagrid view''或任何其他工具保存这些条目。

i不想在表单上使用很多文本框。

plz帮帮我

thankyou ............

i want to save 5 customer details(name,contact no,email id,pan no,landline no,company name,designation,etc.) at same time in sql database.
which control i should use
can i save this entries using ''datagrid view'' or any other tool.
i don''t want to use many textboxes on the form.
plz help me
thankyou............

推荐答案

嗨如果如果要保存可以使用此代码的数据,则需要在datagridview中输入数据。您应该根据需要更改值。

Hi if you want to enter data in datagridview after that you want to save the data you can use this code. You should change the value according to you need.
void SaveEach()
        {
            try
            {
                if (dataGridView1.Rows.Count > 1)
                {
                    for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
                    {
                        string col1 = dataGridView1.Rows[i].Cells[0].Value.ToString();
                        string col2 = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        string col3 = dataGridView1.Rows[i].Cells[2].Value.ToString();
                        string col4 = dataGridView1.Rows[i].Cells[3].Value.ToString();
                        string col5 = dataGridView1.Rows[i].Cells[4].Value.ToString();
                        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
                        {
                            string insert = "INSERT INTO InvoiceItems(InvoiceNo,SNo,Quantity,Rate,Description,Total) VALUES (@InvoiceNo,@SNo,@Quantity,@Rate,@Description,@Total)";
                            con.Open();
                            SqlCommand cmd = new SqlCommand(insert, con);
                            cmd.Parameters.AddWithValue("@InvoiceNo", txt_invoiceno.Text);
                            cmd.Parameters.AddWithValue("@SNo", col1.ToString());
                            cmd.Parameters.AddWithValue("Description", col2.ToString());
                            cmd.Parameters.AddWithValue("@Quantity", col3.ToString());
                            cmd.Parameters.AddWithValue("@Rate", col4.ToString());
                            cmd.Parameters.AddWithValue("Total", col5.ToString());
                            cmd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }







谢谢




Thanks


这篇关于在sql数据库中保存批量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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