Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to update details using linq to entities. But instead of takin a new aspx page i want to update details in another view. will it work.? and please give the linq to entity update query
Let us assume:
db is the context of your Database Entity.
Table_name is the name of Table you need to update.
row_id is the value you are using to search for the data in the Table.
To update using linq you need to fetch the record first using the below query:
var data = (from r in db.Table_name
where r.id == row_id
select r).FirstOrDefault();
Now to update the values just update them. For example:
data.Name = "Firstname lastname"
data.IsActive = true;
.
.
and so on
After you have updated the values in data you need to Save the changes made by you by this command:
db.SaveChanges();
That's it.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am using Microsoft Visual Studio and SQL Server for development.
The problem is initially i upload a file after some time if i upload the another file instead of existing one, then i want to maintain the previous file and also the version are created automatically each time while upload a new file.
Is there any opensource .net API is available to maintain the files with version?
Because i want to show the old files to user when they select roll back option.
Any suggestions please give me how to figure out this...
If you have a database lying around, this can be done with two tables (setting aside the discussion about where to keep actual binary content):
File
----
ID int
Name string(200)
MimeType string(200)
LastRevisionID references Revision.ID, nullable
Revision
----
FileID references File.ID
Content varbinary(max)
When a file is initially uploaded:
begin tran
insert into File ... values ...
insert into Revision .... values ....
update File set LastRevisionID = #lastInsertedRevisionID where ID = #id
commit tran
When a file is updated, first select * from File where Name = #name, remember the LastRevisionID as #lastRevisionID and then:
begin tran
insert into Revision .... values ....
update File set LastRevisionID = #lastInsertedRevisionID
where ID = #id and LastRevisionID = #lastRevisionID
commit tran
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Create an index-by table and populate with rows from emp, then loop over and print them.
hi can anyone understand this question and give me the suggestions to solve this please..
A collection is an ordered group of elements having the same data type
which can be accessed though subscript/index. Oracle PL/SQL supports
three different types of collection
Index-by tables or Associative array
Nested table
Variable-size array or Varray
Below is an example of how you can define a Index-by table and populate it with rows from Emp table and print them accordingly.
DECLARE
CURSOR c_emp is
select name from emp;
TYPE c_list IS TABLE of emp.name%type INDEX BY binary_integer;
name_list c_list;
counter integer :=0;
BEGIN
FOR n IN c_emp LOOP
counter := counter +1;
name_list(counter) := n.name;
dbms_output.put_line('Employee('||counter|| '):'||name_list(counter));
END LOOP;
END;
/
See Oracle Documentation as well as PL/SQL - Collections for more information on the same.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have a table with Photos, allowing multiple rows per AlbumID:
Photos (photoID, photo,caption,albumID).
Albums (albumID,albumTitle)
I want a list of albumTitle and one photo for that albumID.
There are multiple photos in Photos table for a single albumID.
Can you provide a sql statement to select only one Photo per album id?
Thanks in advance!
Avi
SELECT AlbumID, MIN(PhotoID)
FROM PHOTOS
GROUP BY AlbumID
this will return only 1 of each instance of each albumID and a photo
SELECT DISTINCT `albumID `, `photo` FROM `Photos`;
and then you can:
SELECT
DISTINCT `albumID `, `photo`
FROM
`Photos`
INNER JOIN
`Albums`
ON `Albums.albumID` = `Photos.albumID`
AND `Albums.albumTitle` = `albumTitle`
Here's one way to do it using the Max(photoId):
Select a.albumId, a.albumTitle, p.photoId, p.photo, p.caption
From Albums a
Inner Join Photos p On a.albumId = p.albumId
Inner Join (
Select Max(photoId) maxPhotoId, albumId
From Photos
Group By albumId
) t On p.photoId = t.maxPhotoId And a.albumId = t.albumId
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Does anyone know of a script to download email from Gmail and store it to a SQL server? (for backup purposes)
I am looking for a .NET solution (C#).
EML files are plain text.
Simply create a table in your database with one column (and all the others you need, that's for you to decide) of type nvarchar(max) that will store the contents of the email file. For example call this column email_content
Then do something like this:
string email = File.ReadAllText("Path/to/EML/File");
And then do something like:
using (SqlConnection con = new SqlConnection("YourConnectionStringHere"))
{
con.Open();
using(SqlCommand command = new SqlCommand("INSERT INTO your_table (email_content) values (#email_content)",con)
{
command.Parameters.AddWithValue("#email_content",email);
command.ExecuteNonQuery();
}
}
*That's assuming you are using SQL Server but the principle is the same for any other database.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Get the last record from a Microsoft SQL database table using ASP.net (VB) onto a web form.
I'm assuming he's trying to retrieve the last inserted record. As Ariel pointed out, the question is rather ambiguous.
SELECT TOP 1 * FROM Table ORDER BY ID DESC
If you have an identity column called ID, this is easiest. If you don't have an identity PK column for example a GUID you wont be able to do this.
Here is a basic solution:
var order = (from i in db.orders
where i.costumer_id.ToString() == Session["costumer_id"]
orderby i.order_id descending
select i).Take(1).SingleOrDefault();
You need to be more specific with actually putting it onto a web form, but the SQL to get the last record is:
SELECT *
FROM TABLE_NAME
WHERE ID = (SELECT MAX(ID) FROM TABLE_NAME)
Where ID is your ID and TABLE_NAME is your table name.