当前位置: 首页>>代码示例>>C#>>正文


C# SqlDataSource.Insert方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.SqlDataSource.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataSource.Insert方法的具体用法?C# SqlDataSource.Insert怎么用?C# SqlDataSource.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.SqlDataSource的用法示例。


在下文中一共展示了SqlDataSource.Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connstring = "Server=tcp:evansvilledayschoolserver.database.windows.net,1433;Database=EvansvilleDaySchoolDatabase;User [email protected];Password=Quokka12;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
            string selstring = "SELECT * FROM SUBSCRIPTION JOIN USERS ON USERS.USER_ID = SUBSCRIPTION.USER_ID JOIN LIST ON SUBSCRIPTION.LIST_ID =  LIST.LIST_ID";

            string phone = Label1.Text + Label4.Text + Label5.Text;
            string fname = Label2.Text;
            string lname = Label3.Text;
            string lists = Label6.Text;

            SqlDataSource db = new SqlDataSource(connstring, selstring);
            DataView dv = (DataView)db.Select(DataSourceSelectArguments.Empty);
            string FirstName = (string)dv.Table.Rows[0][4];
            string LastName = (string)dv.Table.Rows[0][5];
            string Phone = (string)dv.Table.Rows[0][6];
            int userid = (int)dv.Table.Rows[0][0];
            string updatestring = String.Format("UPDATE USERS SET USER_FNAME={0}, USER_LNAME={1}, USER_PHONE={2} WHERE USER_ID={3};", fname, lname, phone, userid);
            db.UpdateCommand = updatestring;
            //db.InsertCommand = insertstring;

            if (FirstName == Label2.Text && LastName == Label3.Text)
            {
                string firstUpdateString = String.Format("UPDATE USERS SET USER_FNAME={0}, USER_LNAME={1}, USER_PHONE={2} WHERE USER_ID={3};", fname, lname, phone, userid);
                db.UpdateCommand = updatestring;
                db.Update();
            }
            else
            {
                string insertstring = String.Format("INSERT INTO USERS VALUES {0},{1},{2}", fname, lname, phone);
                db.Insert();
                insertstring = String.Format("INSERT INTO SUBSCRIPTION VALUES {0}", lists);
                db.InsertCommand = insertstring;
                db.Insert();
            }

            Response.Redirect("TextAlertRegistration.aspx");
        }
开发者ID:usiwallaby,项目名称:CS478-RelayEngine,代码行数:37,代码来源:regConf.aspx.cs

示例2: DuplicateProject

        public static bool DuplicateProject(string projectID, string projectNewName)
        {
            SqlDataSource dataSource = new SqlDataSource();
            // Super bad? Copy pasta from web.config
            dataSource.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\sunspace_db.mdf;Integrated Security=True;Connect Timeout=30";
            Project aProject = new Project();
            System.Data.DataView selectProject = new System.Data.DataView();
            string sqlSelect;
            string sqlInsert;
            List<string> tableNames = new List<string>();
            int newProjectID;   // New project ID for all the compenents of a project
            int tableCount;     // Number of tables

            // Select the project
            sqlSelect = "SELECT 	project_type," +
                                    "installation_type," +
                                    "customer_id," +
                                    "user_id," +
                                    "date_created," +
                                    "status," +
                                    "revised_date," +
                                    "revised_user_id," +
                                    "msrp," +
                                    "project_notes," +
                                    "hidden," +
                                    "cut_pitch" +
                        " FROM Projects" +
                        " WHERE project_ID = " + projectID + ";";

            dataSource.SelectCommand = sqlSelect;
            selectProject = (System.Data.DataView)dataSource.Select(System.Web.UI.DataSourceSelectArguments.Empty);

            Debug.WriteLine(selectProject[0].Row[0]);

            // Insert the new project with the duplicated data!
            sqlInsert = "INSERT INTO Projects(project_type, " +
                     "installation_type, " +
                     "customer_id, " +
                     "user_id, " +
                     "date_created, " +
                     "status, " +
                     "revised_date, " +
                     "revised_user_id, " +
                     "msrp, " +
                     "project_notes, " +
                     "hidden, " +
                     "cut_pitch, " +
                     "project_name " +
            ") VALUES ( '" + selectProject[0].Row[0] + "'," +
                     "'" + selectProject[0].Row[1] + "'," +
                     "'" + selectProject[0].Row[2] + "'," +
                     "'" + selectProject[0].Row[3] + "'," +
                     "'" + selectProject[0].Row[4] + "'," +
                     "'" + selectProject[0].Row[5] + "'," +
                     "'" + selectProject[0].Row[6] + "'," +
                     "'" + selectProject[0].Row[7] + "'," +
                     "'" + selectProject[0].Row[8] + "'," +
                     "'" + selectProject[0].Row[9] + "'," +
                     "'" + selectProject[0].Row[10] + "'," +
                     "'" + selectProject[0].Row[11] + "'," +
                     "'" + projectNewName + "' ); "; //+
            //" WHERE project_ID = '" + projectID + "';";

            dataSource.InsertCommand = sqlInsert;
            dataSource.Insert();

            // Grab project id from the last insert!
            sqlSelect = "SELECT project_ID from Projects WHERE project_ID = IDENT_CURRENT('Projects');";

            dataSource.SelectCommand = sqlSelect;
            selectProject = (System.Data.DataView)dataSource.Select(System.Web.UI.DataSourceSelectArguments.Empty);

            // Set new project id
            newProjectID = (int)selectProject[0].Row[0];

            Debug.WriteLine(selectProject[0].Row[0]);

            // Get table count
            sqlSelect = "Select Count(*) From INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'project_id' AND TABLE_NAME <> 'projects'";

            dataSource.SelectCommand = sqlSelect;
            selectProject = (System.Data.DataView)dataSource.Select(System.Web.UI.DataSourceSelectArguments.Empty);

            // Set table count
            tableCount = (int)selectProject[0].Row[0];

            Debug.WriteLine(selectProject[0].Row[0]);

            // Essentially this gets a compenent table info and re-inserts it with the new project ID
            for (int index = 0; index < tableCount; index++)
            {
                // Get table names
                sqlSelect = "SELECT TABLE_NAME From INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE 'project_id' AND TABLE_NAME <> 'projects' ORDER BY TABLE_NAME ASC OFFSET "+ index +" ROWS FETCH NEXT 1 ROWS ONLY";
                dataSource.SelectCommand = sqlSelect;
                selectProject = (System.Data.DataView)dataSource.Select(System.Web.UI.DataSourceSelectArguments.Empty);

                tableNames.Add((string)selectProject[0].Row[0]);
                Debug.WriteLine("Table Name: " + selectProject[0].Row[0]);
                Debug.WriteLine("Table Count:" + tableNames.Count());

//.........这里部分代码省略.........
开发者ID:kbrougham,项目名称:Sunspace,代码行数:101,代码来源:SavedProjects.aspx.cs


注:本文中的System.Web.UI.WebControls.SqlDataSource.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。