public static void Init() { dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;"); var sqlUtil = new SqlUtil(dbConnection); if (!sqlUtil.Exists("Person")) { sqlUtil.ExecuteNonQuery("Create table Person(EmpID int, Name varchar(50), Age int)"); sqlUtil.ExecuteNonQuery("insert into Person(EmpID , Name , Age ) select 1, 'sakthi', 40 "); sqlUtil.ExecuteNonQuery("insert into Person(EmpID , Name , Age ) select 2, 'sakthi2', 41 "); } }
protected void post_Click(object sender, EventArgs e) { //Guid CompanyID = Guid.NewGuid(); List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@uid", Session["uid"])); parameters.Add(new SqlParameter("@Major", major.Text)); parameters.Add(new SqlParameter("@Classification", classification.Text)); parameters.Add(new SqlParameter("@College", college.Text)); parameters.Add(new SqlParameter("@Term", term.Text)); parameters.Add(new SqlParameter("@Name", company.Text)); parameters.Add(new SqlParameter("@Position", position.Text)); parameters.Add(new SqlParameter("@Country", country.Text)); parameters.Add(new SqlParameter("@State", state.Text)); parameters.Add(new SqlParameter("@City", city.Text)); parameters.Add(new SqlParameter("@Resources_Used", resources.Text)); parameters.Add(new SqlParameter("@Long_Disc", description.Text)); parameters.Add(new SqlParameter("@Lessons_Learned", lessons.Text)); parameters.Add(new SqlParameter("@Twitter", twitter.Text)); parameters.Add(new SqlParameter("@LinkedIn", linkedIn.Text)); parameters.Add(new SqlParameter("@Facebook", facebook.Text)); int row = SqlUtil.ExecuteNonQuery("INSERT INTO Intern_Posting (ID_Num,Major, Classification, College, Term, " + "Position, Resources_Used,Long_Disc,Lessons_Learned, Twitter, LinkedIn, Facebook,Company,Country,State,City,Date) VALUES (@uid, @Major, " + "@Classification,@College, @Term,@Position,@Resources_Used, @Long_Disc, @Lessons_Learned, @Twitter, @LinkedIn, @Facebook,@Name,@Country,@State," + "@City,GETDATE())", parameters); }
protected void button_rebuild_Click(object sender, EventArgs e) { string path = System.Web.HttpContext.Current.Server.MapPath(@"~/sql/database_build_query.sql"); string q = File.ReadAllText(path); SqlUtil.ExecuteNonQuery(q); }
protected void SecuritySubmit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("uid", Session["uid"])); parameters.Add(new SqlParameter("password", Password.Text)); SqlDataReader reader = SqlUtil.ExecuteReader("SELECT * FROM User_Main WHERE Password = @password AND ID_NUM = @uid", parameters); if (!reader.Read()) { Error.Text = "Incorrect password."; reader.Close(); return; } reader.Close(); parameters.Clear(); parameters.Add(new SqlParameter("password", NewPassword.Text)); parameters.Add(new SqlParameter("uid", Session["uid"])); SqlUtil.ExecuteNonQuery("UPDATE User_Main SET Password = @password WHERE ID_Num = @uid", parameters); Password.Text = ""; NewPassword.Text = ""; NewPassword2.Text = ""; }
protected void submit_Click(object sender, EventArgs e) { Guid blogID = Guid.NewGuid(); List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@title", title.Text)); parameters.Add(new SqlParameter("@body", body.Text)); parameters.Add(new SqlParameter("@uid", Session["uid"])); parameters.Add(new SqlParameter("@blogid", blogID)); int rows = SqlUtil.ExecuteNonQuery("INSERT INTO Blog_Post (BlogID, ID_Num, Title, Body, Date) VALUES (@blogid, @uid, @title, @body, GETDATE())", parameters); if (rows == 1) { if (!string.IsNullOrWhiteSpace(tags.Text)) { string[] tags_array = tags.Text.Split(' '); foreach (string tag in tags_array) { List <SqlParameter> tag_parameters = new List <SqlParameter>(); tag_parameters.Add(new SqlParameter("@blogid", blogID)); tag_parameters.Add(new SqlParameter("@tag", tag)); rows = SqlUtil.ExecuteNonQuery("INSERT INTO Tags (BlogID, Tag) VALUES (@blogid, @tag)"); } } Response.Redirect("View/" + blogID); } }
protected void submit_Click(object sender, EventArgs e) { Error.Text = ""; List <SqlParameter> check_parameters = new List <SqlParameter>(); check_parameters.Add(new SqlParameter("@email", email.Text)); SqlDataReader reader = SqlUtil.ExecuteReader("SELECT * FROM User_Main WHERE Email = @email", check_parameters); if (reader.Read()) { Error.Text = "A user with that email alreader exists."; reader.Close(); return; } reader.Close(); List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@email", email.Text)); parameters.Add(new SqlParameter("@fname", fname.Text)); parameters.Add(new SqlParameter("@lname", lname.Text)); parameters.Add(new SqlParameter("@password", password.Text)); int rows = SqlUtil.ExecuteNonQuery("INSERT INTO User_Main (Email, User_Type, Fname, Lname, Last_Login, Password) VALUES (@email, 2, @fname, @lname, GETDATE(), @password)", parameters); if (rows == 1) { Response.Redirect("Main.aspx"); } }
protected void Cpost_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@uid", Session["uid"])); parameters.Add(new SqlParameter("@Major", major.Text)); parameters.Add(new SqlParameter("@College", college.Text)); parameters.Add(new SqlParameter("@Graduation", graduation.Text)); parameters.Add(new SqlParameter("@Name", company.Text)); parameters.Add(new SqlParameter("@Position", position.Text)); parameters.Add(new SqlParameter("@Country", country.Text)); parameters.Add(new SqlParameter("@State", state.Text)); parameters.Add(new SqlParameter("@City", city.Text)); parameters.Add(new SqlParameter("@Resources_Used", resources.Text)); parameters.Add(new SqlParameter("@Long_Disc", description.Text)); parameters.Add(new SqlParameter("@Lessons_Learned", lessons.Text)); parameters.Add(new SqlParameter("@Industry", industry.Text)); parameters.Add(new SqlParameter("@Email", email.Text)); parameters.Add(new SqlParameter("@Instagram", instagram.Text)); parameters.Add(new SqlParameter("@Twitter", twitter.Text)); parameters.Add(new SqlParameter("@LinkedIn", linkedIn.Text)); parameters.Add(new SqlParameter("@Facebook", facebook.Text)); int row = SqlUtil.ExecuteNonQuery("INSERT INTO Job_Posting (ID_Num, Major,College, Graduation, " + "Position, Resources_Used,Long_Disc,Lessons_Learned,Industry,Email,Instagram, Twitter, LinkedIn, Facebook,Company,Country,State,City,Date) VALUES (@uid, @Major, " + "@College, @Graduation,@Position,@Resources_Used, @Long_Disc, @Lessons_Learned,@Industry, @Email, @Instagram,@Twitter, @LinkedIn, @Facebook,@Name,@Country,@State," + "@City,GETDATE())", parameters); }
protected void post_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@ID_Num", Session["uid"])); parameters.Add(new SqlParameter("@Major", major.Text)); parameters.Add(new SqlParameter("@Classification", classification.Text)); parameters.Add(new SqlParameter("@College", college.Text)); parameters.Add(new SqlParameter("@Term", term.Text)); parameters.Add(new SqlParameter("@Name", company.Text)); parameters.Add(new SqlParameter("@Position", position.Text)); parameters.Add(new SqlParameter("@Country", country.Text)); parameters.Add(new SqlParameter("@State", state.Text)); parameters.Add(new SqlParameter("@City", city.Text)); parameters.Add(new SqlParameter("@Resources_Used", resources.Text)); parameters.Add(new SqlParameter("@Long_Disc", description.Text)); parameters.Add(new SqlParameter("@Lessons_Learned", lessons.Text)); parameters.Add(new SqlParameter("@Twitter", twitter.Text)); parameters.Add(new SqlParameter("@LinkedIn", linkedIn.Text)); parameters.Add(new SqlParameter("@Facebook", facebook.Text)); int reader = SqlUtil.ExecuteNonQuery("INSERT INTO Intern_Posting (ID_Num, Major, Classification, College, Term, Position, Resources_Used, [Long_Disc.]," + "Lessons_Learned, Twitter, LinkedIn, Facebook) " + "VALUES (@ID_NUm, @Major, @Classification,@College, @Term,@Position,@Resources_Used, @Long_Disc, @Lessons_Learned, @Twitter, @LinkedIn, " + "@Facebook)", parameters); //int reader2 = SqlUtil.ExecuteNonQuery("INSERT INTO User_Company(Name,Country, State, City) " + // "VALUES(@Name,@Country,@State,@City)", parameters); }
protected void submit_vote_click(object sender, EventArgs e) { List <SqlParameter> p = new List <SqlParameter>(); p.Add(new SqlParameter("@VoteID", Guid.NewGuid())); p.Add(new SqlParameter("@ID_Num", Session["uid"])); if (option1.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[0])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option2.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[1])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option3.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[2])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option4.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[3])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option5.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[4])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option6.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[5])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option7.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[6])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option8.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[7])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option9.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[8])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } else if (option10.Checked) { p.Add(new SqlParameter("@Option_ID", id_list[9])); SqlUtil.ExecuteNonQuery("insert into [Votes] values (@VoteID,@Option_ID,@ID_Num)", p); } Response.Redirect(Request.RawUrl); }
protected void unfollow_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("uid", Session["uid"])); parameters.Add(new SqlParameter("follow_uid", Guid.Parse(uid))); SqlUtil.ExecuteNonQuery("DELETE FROM BlogFollowers WHERE Following = @follow_uid AND Follower = @uid", parameters); }
protected void follow_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("uid", Session["uid"])); parameters.Add(new SqlParameter("follow_uid", Guid.Parse(uid))); SqlUtil.ExecuteNonQuery("INSERT INTO BlogFollowers (Following, Follower) VALUES (@follow_uid, @uid)", parameters); }
public int Delete(int id) { var sql = $"DELETE FROM RedirectManager WHERE id = {id}"; Logger.Debug("Start Delete()"); Logger.Debug($"SQL: {sql}"); return(SqlUtil.ExecuteNonQuery(sql)); }
public int DeleteAll() { var sql = $"DELETE FROM RedirectManager"; Logger.Debug("Start DeleteAll()"); Logger.Debug($"SQL: {sql}"); return(SqlUtil.ExecuteNonQuery(sql)); }
public int RemoveAndInsert(RedirectManagerModel model) { var sql = $"delete from RedirectManager where OldUrl = '{model.OldUrl}'; " + $"insert into RedirectManager values ('{model.OldUrl}', '{model.NewUrl}', {model.Type}, {(model.IncludeQuery ? 1 : 0)})"; Logger.Debug("Start RemoveAndInsert()"); Logger.Debug($"SQL: {sql}"); return(SqlUtil.ExecuteNonQuery(sql)); }
protected void Submit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("title", title.Text)); parameters.Add(new SqlParameter("body", Body.Text)); parameters.Add(new SqlParameter("blogid", blogID)); SqlUtil.ExecuteNonQuery("UPDATE Blog_Post SET Title = @title, Body = @body WHERE BlogID = @blogid", parameters); }
protected void new_post_submit_click(object sender, EventArgs e) { int board = (int)Session["board"]; List <SqlParameter> parameters = new List <SqlParameter>(); Guid g = Guid.NewGuid(); parameters.Add(new SqlParameter("@BpostID", g)); parameters.Add(new SqlParameter("@ID_Num", Session["uid"])); parameters.Add(new SqlParameter("@Title", new_post_title.Text)); parameters.Add(new SqlParameter("@Description", new_post_description.Text)); parameters.Add(new SqlParameter("@Board", board)); parameters.Add(new SqlParameter("@Date", DateTime.Now)); parameters.Add(new SqlParameter("@Expiration", DateTime.MaxValue)); //parameters.Add(new SqlParameter("@Tags", null)); parameters.Add(new SqlParameter("@Attachments", (Byte[])Session["image_array"])); int reader = SqlUtil.ExecuteNonQuery("insert into board_post values (@BpostID,@ID_Num,@Title,@Description,@Board,@Date,@Expiration,null,@Attachments,default,default)", parameters); if (board == 2) { List <string> options = (List <string>)Session["options"]; foreach (string o in options) { if (o != "") { parameters.Clear(); parameters.Add(new SqlParameter("@Text", o)); parameters.Add(new SqlParameter("@BpostID", g)); parameters.Add(new SqlParameter("@option_id", Guid.NewGuid())); SqlUtil.ExecuteNonQuery(("insert into [poll_options] values (@option_id, @BpostID, @Text)"), parameters); } } } Session.Add("options", null); Session.Add("edit", null); Session.Add("title", null); Session.Add("description", null); Session.Add("image", null); Session.Add("last_tab", null); Session.Add("last_radio", null); string link = "view/" + g; Response.Redirect(link); }
protected void Submit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("blogid", blogID)); parameters.Add(new SqlParameter("uid", Session["uid"])); parameters.Add(new SqlParameter("name", Name.Text)); parameters.Add(new SqlParameter("comment", Comment.Text)); SqlUtil.ExecuteNonQuery("INSERT INTO Post_Comment (BlogID, ID_Num, Name, Date, Comment) VALUES (@blogid, @uid, @name, GETDATE(), @comment)", parameters); }
protected void Submit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@id", id)); parameters.Add(new SqlParameter("@type", post_type)); parameters.Add(new SqlParameter("@reporter", Session["uid"])); parameters.Add(new SqlParameter("@date", DateTime.Now)); parameters.Add(new SqlParameter("@comment", Comment.Text)); SqlUtil.ExecuteNonQuery("INSERT INTO Moderation (PostId, Type, ID_Num, Date, Comment, Mod_Status) VALUES (@id, @type, @reporter, @date, @comment, 1)", parameters); }
public int InsertOrUpdate(RedirectManagerModel model) { var sql = $"insert into RedirectManager values ('{model.OldUrl}', '{model.NewUrl}', {model.Type}, {(model.IncludeQuery ? 1 : 0)})"; if (model.Id > 0) { sql = $"UPDATE RedirectManager SET OldUrl = '{model.OldUrl}', NewUrl = '{model.NewUrl}', RedirectType = {model.Type}, IncludeQuery = {(model.IncludeQuery ? 1 : 0)} where id = {model.Id}"; } Logger.Debug("Start InsertOrUpdate()"); Logger.Debug($"SQL: {sql}"); return(SqlUtil.ExecuteNonQuery(sql)); }
protected void button_populate_users_Click(object sender, EventArgs e) { int number_of_users = Convert.ToInt32(textbox_number_users.Value); string path = System.Web.HttpContext.Current.Server.MapPath(@"~/sql/pop_users.sql"); //string pop_users = File.ReadAllText(path); string[] pop_users = File.ReadAllLines(path); if (number_of_users < 1000) { for (int i = 0; i < number_of_users; i++) { SqlUtil.ExecuteNonQuery(pop_users[i]); } } }
protected void submit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@email", email.Text)); parameters.Add(new SqlParameter("@fname", fname.Text)); parameters.Add(new SqlParameter("@lname", lname.Text)); parameters.Add(new SqlParameter("@password", password.Text)); int rows = SqlUtil.ExecuteNonQuery("INSERT INTO User_Main (Email, User_Type, Fname, Lname, Last_Login, Password) VALUES (@email, 2, @fname, @lname, GETDATE(), @password)", parameters); if (rows == 1) { Response.Redirect("Main.aspx"); } }
protected void GeneralSubmit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("fname", FirstName.Text)); parameters.Add(new SqlParameter("lname", LastName.Text)); parameters.Add(new SqlParameter("major", Major.Text)); parameters.Add(new SqlParameter("classification", Classification.Text)); parameters.Add(new SqlParameter("phone", Phone.Text)); parameters.Add(new SqlParameter("org", OrgAffiliation.Text)); parameters.Add(new SqlParameter("uid", Session["uid"])); SqlUtil.ExecuteNonQuery("UPDATE User_Main SET Fname = @fname, Lname = @lname, Major = @major," + " Classification = @classification, Phone = @phone, Org_Affiliation = @org WHERE ID_Num = @uid", parameters); }
protected void Submit_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@Title", title.Text)); parameters.Add(new SqlParameter("@Image", Picture.Text)); parameters.Add(new SqlParameter("@Tags", Tags.Text)); parameters.Add(new SqlParameter("@Discription", Description.Text)); int rows = SqlUtil.ExecuteNonQuery("INSERT INTO Gallery_Post (Title, Image, Tags, Date, Discription) VALUES (@Title, @Image, @Tags, GETDATE(), @Discription)", parameters); if (rows == 1) { Response.Redirect("Main.aspx"); } }
protected void post_Click(object sender, EventArgs e) { List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@major", major.Text)); parameters.Add(new SqlParameter("@classification", classification.Text)); parameters.Add(new SqlParameter("@term", term.Text)); parameters.Add(new SqlParameter("@company", company.Text)); parameters.Add(new SqlParameter("@position", position.Text)); parameters.Add(new SqlParameter("@state", state.Text)); parameters.Add(new SqlParameter("@city", city.Text)); parameters.Add(new SqlParameter("@description", description.Text)); parameters.Add(new SqlParameter("@lessons", lessons.Text)); parameters.Add(new SqlParameter("@email", email.Text)); parameters.Add(new SqlParameter("@twitter", twitter.Text)); parameters.Add(new SqlParameter("@linkedIn", linkedIn.Text)); parameters.Add(new SqlParameter("@facebook", facebook.Text)); parameters.Add(new SqlParameter("@instagram", instagram.Text)); parameters.Add(new SqlParameter("@phone", phone.Text)); int reader = SqlUtil.ExecuteNonQuery("INSERT INTO User_Company(country,state,city,email) VALUES (@country,@state,@city,@email)", parameters); int reader1 = SqlUtil.ExecuteNonQuery("INSERT INTO Job_Posting(position,Long_Disc,Skills_Req) VALUES (@position,@description,@lessons)", parameters); }
public void Process(string connectionString, string tableName) { string primaryKeyFieldName = SplitTableConfigHelper.GetConfigValue(connectionString, tableName, "PrimaryKeyFieldName"); string createTableScript = SplitTableConfigHelper.GetConfigValue(connectionString, tableName, "ArchiveTableScript"); string archiveWhereSql = SplitTableConfigHelper.GetConfigValue(connectionString, tableName, "ArchiveSQL"); //把上个月、已完成的转入Archive表 //把上个月、IsDeleted=1的转入Archive表 DateTime yesterday = DateTime.Now.AddDays(-1); string contentArchiveTableName = string.Format("{0}.Archived.{1}", tableName, yesterday.ToString("yyyyMMdd")); createTableScript = string.Format(createTableScript, contentArchiveTableName); string createContentArchiveTableSql = @" IF NOT EXISTS( SELECT 1 FROM [SplitTableMappings](NOLOCK) WHERE [PhysicalTableName]='" + contentArchiveTableName + @"' AND [LogicalTableName]='" + tableName + @"' ) BEGIN " + createTableScript + @" END IF NOT EXISTS( SELECT 1 FROM [SplitTableMappings](NOLOCK) WHERE [PhysicalTableName]='" + contentArchiveTableName + @"' AND [LogicalTableName]='" + tableName + @"' ) BEGIN INSERT INTO [SplitTableMappings](LogicalTableName, PhysicalTableName) VALUES('" + tableName + @"', '" + contentArchiveTableName + @"') END "; SqlUtil.ExecuteNonQuery(connectionString, createContentArchiveTableSql); string selectHotTableNamesSql = "SELECT [PhysicalTableName] FROM [SplitTableMappings](NOLOCK) WHERE HotTable=1 AND LogicalTableName='" + tableName + "'"; List <string> hotTables = SqlUtil.GetStringList(connectionString, selectHotTableNamesSql); foreach (var hotTable in hotTables) { if (hotTable == contentArchiveTableName) { continue; } string sql = @" BEGIN TRY TRUNCATE TABLE ##MoveRecords END TRY BEGIN CATCH END CATCH BEGIN TRY DROP TABLE ##MoveRecords END TRY BEGIN CATCH END CATCH SELECT * INTO ##MoveRecords FROM ( SELECT TOP 500 * FROM [" + hotTable + @"](READPAST) WHERE " + archiveWhereSql + @" ) TBL BEGIN TRANSACTION DELETE FROM [" + hotTable + @"] WHERE [" + primaryKeyFieldName + @"] IN (SELECT [" + primaryKeyFieldName + @"] FROM ##MoveRecords(NOLOCK)) INSERT INTO [" + contentArchiveTableName + @"] SELECT * FROM ##MoveRecords(NOLOCK) COMMIT TRANSACTION DROP TABLE ##MoveRecords "; SqlUtil.ExecuteNonQuery(connectionString, sql); } }