本文整理汇总了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");
}
示例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());
//.........这里部分代码省略.........