TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paul Arthur
NA
12
3k
INSERT INTO SQL Server with C# and ASP.NET
Nov 23 2015 10:33 AM
Hello,
I am very new to the technologies of ASP.NET and C#.
I currently have a GridView that is in edit mode. All I want to do is insert data from the grid into SQL server as a completely new record. The select statement I have that populates the GridView is only looking at the latest record so I have a kind of audit trail. Thus I don't need to do an update I need to do an insert into.
When someone clicks update button its not running the SQL and there is also no error. The browser looks like its doing something but as I said the SQL is not executed.
protected void MainGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlDataSource SqlDataSource2 = new SqlDataSource();
SqlDataSource2.ID = "SqlDataSource2";
this.Page.Controls.Add(SqlDataSource2);
SqlDataSource2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["RMUConnectionString"].ConnectionString;
SqlDataSource2.SelectCommand = @"INSERT INTO [CQUIN DATA TABLE]
([Contract Number], [Lead PCT], [BMI Site], [CQUIN Indicator], [Achievement Reported by site (% of individual indicator)], [Quarter], ODScode, Date_Updated, [User], [Agreed by CCG])
VALUES (@s_contract, @s_lead_ccg, @s_bmi_site, @s_cquin_indicator, @s_achievement, @Year + ' ' + @Quarter, @Site, GETDATE(), 'TEST', @s_agreed)";
SqlDataSource2.SelectParameters.Add("s_contract", MainDataView.Rows[0].Cells[0].Text);
SqlDataSource2.SelectParameters.Add("s_lead_ccg", MainDataView.Rows[0].Cells[1].Text);
SqlDataSource2.SelectParameters.Add("s_bmi_site", MainDataView.Rows[0].Cells[2].Text);
SqlDataSource2.SelectParameters.Add("s_ods", MainDataView.Rows[0].Cells[3].Text);
SqlDataSource2.SelectParameters.Add("s_cquin_indicator", MainDataView.Rows[0].Cells[4].Text);
SqlDataSource2.SelectParameters.Add("s_weighting", MainDataView.Rows[0].Cells[5].Text);
SqlDataSource2.SelectParameters.Add("s_achievement", MainDataView.Rows[0].Cells[6].Text);
SqlDataSource2.SelectParameters.Add("s_agreed", MainDataView.Rows[0].Cells[7].Text);
//MainDataView.EditIndex = -1;
SqlDataSource2.DataBind();
}
Any help would be greatly appreciated.
Paul
Reply
Answers (
1
)
CSS: How to change colour of active navigation page menu
how can I reduce my project size in Visual Studio