DataSource Controls :: How To Define A Field Value For Deleting A Data Row
Mar 12, 2010
From my Employees table of the Northwind database, how do I delete a row? I have a row with a LastName field = WWWW How to write the string sql?
SqlConnection con = new
SqlConnection(connectionString);
string sql =
"DELETE FROM Employees WHERE LastName =" + WWWW;
SqlCommand cmd =
new
SqlCommand(sql, con);
I can use similar code below to select a row in my database when I enter a value (username) in text box and it successfully retrieves.however, I'd also like to delete row from database based on the username i enter in text box. My code runs but no row is deleted...my code is:
I'm looking for ideas on deleting data from the multiple SQL tables with LINQ (C#).
My existing solution does the following:
1. DeleteAllOnSubmit( Subset of the data from the child table)
2. DeleteAllOnSubmit( Subset of the data from another child table)
3. DeleteAllOnSubmit( Data from the parent table)
4. CommitChanges()
All this resides within a single method, which makes it ugly and not re-usable.
I have considered the following alternatives, but I decided not to use them:
1. Cascade delete on the tables.
2. Do a join on all tables from which I will remove the data, but I'm not sure yet whether I could pass a join query to DeleteAllOnSubmit().
3. Write stored procedure(s) to delete data from each table. I don't have the time to implement this due to a large number of tables and the time constraints.
I'm using the asp.net membership on my website. On the User Administration page i've got a GridView to show the details of the users on the site. As a datasource rather than just using the Membership.GetAllUsers function i've got a SQLDataSource as i need to display user information from 3 different tables. I'm trying to add a delete button to the GridView. I'm setting the Membership's UserName as a DataKey and then using the RowDeleting event to call Membership.DeleteUser for the appropriate UserName. This works fine and the user is deleted however i then get an error showing up that "Deleting is not supported by data source 'SqlDataSource1' unless DeleteCommand is specified."
I don't want to use the SqlDataSource for deleting as i've already done it using the Membership. How can i stop it from trying to do this? Here is the cut-down that i have if you're interested. The selectcommand in the sqldatasource was auto-generated by it.
I am using 3 web controls ,two are cascading dropdownlists used to filter gridview control bound to a datasource.
My question is , How to define multiple queries in stored procedure that takes parameter values from the controls declared using sqldatasource.Also, return all data when i set default control value to say 'null'.
NB: one paramaterised query for cascading dropdownlists and another for other control.
I have 3 tables User, role and UserInRole THe entity frame work made entities for User and Role and I have successfully made a join with the user and role entities using user.add(role); but I can't seem to get it to remove the link (I want to retain the user and role just remove their association).
using (ProviderEntities context = new ProviderEntities()) { User u = context.User .Where(n => n.ApplicationName == application) .Where(n => n.Username == username).First(); Roles r = context.Roles .Where(n => n.ApplicationName == application) .Where(n => n.RoleName == roleName) .First(); r.User.Remove(u); context.SaveChanges(); }
The oposite worked when I did r.User.Add(u); but it wont let me now remove it after it been created. Driving me mad as I can't see where I have gone wrong.
I have bounded my GridView to an ObjectDataSource. I have set a delete method for this ObjectDataSource. Now how can I delete my GridView's records with enable Deleting?
how can i retrieve the all foreign keys against a single primary key. i mean to say that if a table contain a primary key then it becomes as foreign keys in which tables.
i want to take that nam of that tables and on the base of that tables then i am to delete from all the entries. e.g: if a primary key's column entry deleted then all foreing key entries should also be deleted.
there are 988 tables in a single database. it can't be possible to go for each table to setup foreign key to ON DELETE CASCADE.
.can it have any way to delete against foreign key priority wise? mean to say that parent table contain primary key, child table contain foreign key , now there is another child table which dependent previous child table. then how can i delete all record against it?
i want to do it from programatically. i am using sql server 2005
i have completed this till to that , it retrieves all foreign keys but how to delete now on the base of priority.
I have a 20 to 30 fields on a form. Most of them are optional. However, the users can fill out what they want. If a user dosen't fill in a field when data is sent to the database it's sent as blank, instead of NULL. Is there a way I can generically say "for all textboxes if Equals("") then DBNull.Value". Without going through each and every textbox?
I am attempting to compare one of ASP.NET's membership userID's with the current userID in an SQL query, however because of the "hyphens -" in the uniqueidentifier field type of userID, i am unable to compare the ids. is there a way around this? (in my example, family_id from tblFamily is the userID that has type uniqueidentifier). my code as it stands is:
Dim UserID As String = New String(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString()) Response.Write(UserID) Dim strConn As String = ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString Dim SQLI As New Data.SqlClient.SqlCommand("SELECT family_name FROM tblFamily WHERE [family_id] IS " & UserID & "") Dim sqlCon As New Data.SqlClient.SqlConnection(strConn) sqlCon.Open() SQLI.Connection = sqlCon Dim RSI As Data.SqlClient.SqlDataReader = SQLI.ExecuteReader() RSI.Read() Dim FamilyName As String = "0" While RSI.Read FamilyName = Convert.ToString(RSI("family_name")) End While Response.Write(FamilyName) RSI.Close() sqlCon.Close()
i have a datareader who read from data field from sql server, this field is datetime format now, when this field is null it returns 01/01/1900!! how can i manage it without if or some check, is there a property in datareader or sqlserver properties who i can return null value from datetime field?
I have an Output clause in a SQL statement and I use getutcdate() for a record. Does UTC record seconds? If so, how do I display it? What data type should I use for the UTC field?
how one would retrive a value stored among several values in a single database field?
For example, the MS Customize CreateUserWizard walkthrough [URL] adds the ability to save the users preference for subscribing to a newsletter and allowing their info to be shared as 1 value in the comment column of the membership database. The result ofaspnet_Membership.Comment is Subscribe=TRUE&ShareInfo=FALSE.
My question is if Subscribe=TRUE&ShareInfo=FALSE is in one field of the database, how would you retrieve just the Subscribe=TRUE value from the field and use it to send a newsletter to the proper users while ignoring the ShareInfo=FALSE value?
I am trying to explode some data from an ntext field into a cvs for import, here is what i have so far,
DECLARE @XML as XML DECLARE @hDoc as INT SET @XML = (SELECT billaddress FROM order WHERE id=7 ) exec sp_xml_prepairedocument @hDoc OUTPUT, @XML SELECT firstname FROM OPENXML (@hDoc, '//') WITH (type text './type/@text', FirstName text './FirstName/@text') exec sp_xml_removedocument @hDoc OUTPUT
here is the errors:
Msg 2812, Level 16, State 62, Line 4
Could not find stored procedure 'sp_xml_prepairedocument'.
Msg 8179, Level 16, State 5, Line 6
Could not find prepared statement with handle 0.
Msg 6607, Level 16, State 3, Procedure sp_xml_removedocument, Line 1
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.
I have a situation where I have a file with each Account Record contains Monthly Expense Total Fields and Monthly Budget Fields for 2009, 2008 and 2007. I'm working with 72 fields (36 Expense and 36 Budget).
Need to create New Year Proceure that will shift data from 2008 to 2007, 2009 to 2008 and move Zeros to 2009 for both Expenses and Budgets.
I can do this using Parameters and Update SQL but I am under the impression that I must specificaly name each field in defining Parameters and SQL Update Command.
Since all fields are sequential withing a record, is there a way that I can use a For/Next loop to index my way through the fields moving data from one year to another?
When using DataReader I'm able to use reader.item(index) to access data record fields.
How do I bound a Label to a datasource and its field?I got set up the datasource to a gridview, but don't know how to bind a label to the same datasource.
I'm using the 'Configure Data Source' wizard to connect to my database and show the dataset in Gridview. I want to be able to update, insert and delete entries but am unsure how to build the query. I can write simple update statments to change database entries but how can I do this for entries that have been changed within the gridview?