如何在数据库中的diferrent-2行中保存多个文本框值 [英] How to save Multiple textbox values in diferrent-2 Rows in Database

查看:94
本文介绍了如何在数据库中的diferrent-2行中保存多个文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to save Multiple textbox values in diferrent-2 Rows in Database at a time-

Like-

Textbox1.Text="John";

Textbox1.Text="Marcus";

Textbox1.Text="Megan";

Sql Table-

ID   Name
1     John
2     Marcus
3     Megan

Can Anybody tell me the solution plz...

推荐答案

您可以运行查询来插入您的值...



自从你有3个文本框你可以做到在for循环或你决定采用的任何其他神奇方式,



http://www.w3schools.com/sql/sql_insert.asp [ ^ ]
You can run a query to insert your values ...

And since you have 3 text boxes you could do it in a for loop or whatever other magical way you decide to,

http://www.w3schools.com/sql/sql_insert.asp[^]


希望它能为您提供帮助。



Hope so it will help you.

class MultiPleValues
    {
        DataTable dt;

        private void Insert()
        {
            try
            {
                dt = GetDataTable();

                //You can use following in loop. or as your requirement.
                DataRow dr = dt.NewRow();
                dr.BeginEdit();
                dr["S_NO"] = "You Values";
                dr["Name"] = "Your Name";
                dr.EndEdit();
                dt.Rows.Add(dr);


                //After your work compeletition.
                //Insert dt in database useing following method:

                string strQuer = "Select * from --Your Table Name Here";
               dt =  InsertQuery(strQuer, dt);      //this will insert your values in db and also select modified values
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        private DataTable GetDataTable()
        {
            try
            {
                DataTable dtTemp = new DataTable();
                dtTemp.Columns.Add("S_NO");
                dtTemp.Columns.Add("Name");
                return dtTemp;
            }
            catch (Exception)
            {

                throw;
            }
        }


        public static DataTable InsertQuery(string SelectQuery, DataTable dt)
        {
            try
            {
                SqlConnection sqlconn = new SqlConnection("Your Connection String here");
                //this function will insert changes in DB, also select updated values.
                sqlconn.Open();
                SqlCommand sqlcommand = new SqlCommand(SelectQuery, sqlconn);
                SqlDataAdapter adapter = new SqlDataAdapter(sqlcommand);
                SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
                cmdBuilder.ConflictOption = ConflictOption.OverwriteChanges;
                adapter.Update(dt);
                return dt;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }





不要犹豫问任何问题?



Thanx


这篇关于如何在数据库中的diferrent-2行中保存多个文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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