Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2014, 06:31 PM
Authorized User
 
Join Date: Feb 2014
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Figured out insert

what else would I use besides data sets and data tables to bind the information on with a data adapter?

also figured out how do the insert with details view

protected void function2(object sender, DetailsViewInsertEventArgs e)
{
SqlDataAdapter adapt = new SqlDataAdapter();
SqlConnection connect = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["PlanetWroxConnectionString1"].ConnectionString;
SqlCommand command = new SqlCommand();
DataTable table = new DataTable();

command = new SqlCommand("INSERT INTO Genre (Name, SortOrder) VALUES (@Name, @SortOrder)");
command.Parameters.Add("@Name", SqlDbType.NVarChar, 200);
command.Parameters["@Name"].Value = e.Values["Name"].ToString();
command.Parameters.Add("@SortOrder", SqlDbType.Int);
command.Parameters["@SortOrder"].Value = e.Values["SortOrder"].ToString();

command.Connection = connect;

adapt.InsertCommand = command;
connect.Open();
adapt.InsertCommand.ExecuteNonQuery();
connect.Close();
command = new SqlCommand("SELECT * FROM Genre", connect);
adapt.SelectCommand = command;
adapt.Fill(table);

GridView1.DataSource = table.DefaultView;
GridView1.DataBind();

adapt.Dispose();
command.Dispose();
connect.Dispose();
}

used the wrong type of event arguments, but im slightly stuck on the gridview deleting a row, mainly because I don't know how to grab the value of the selected row Id and how to deal between onrowdeleting and onrowdeleted.
 
Old February 21st, 2014, 02:39 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
mainly because I don't know how to grab the value of the selected row Id and how to deal between onrowdeleting and onrowdeleted.
Once again: have you looked into Model Binding as I suggested earlier? With Model Binding your delete method simply gets passed the ID of the item to be selected.

That said, you should be able to retrieve the key using something like this:

Code:
int id = Convert.ToInt32(e.Keys["Id"]);
Quote:
what else would I use besides data sets and data tables to bind the information on with a data adapter?
Not much ;-) But you don't need a data adapter at all. A lot of the code you're posting is "old skool" in my opinion. The things you're doing here are a lot easier with, say, Entity Framework and Model Binding. That way you can focus on your business problems and not spend a lot of time writing boring code to set up parameters and such.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing the Control Adapters Randy-s BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2 5 June 26th, 2009 07:59 AM
CSS Friendly control adapters Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 March 11th, 2009 06:15 AM
ASP.NET CSS Friendly Control Adapters VeganMan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 April 8th, 2008 09:21 PM
Table Adapters mfouchi BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 September 23rd, 2006 05:16 AM
.NET Data Provider pradeep_itguy ADO.NET 0 October 3rd, 2004 04:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.