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.
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
I want to retrieve something from a database in vb.net and display it. It has 4 columns with unlimited amounts of rows, could be 5, could be 10.
First column is an int, second a name, 3rd date and 4th a date. I have to sort it by date. What would be the best way to retrieve all the data and store it?
One solution I thought of was to store each individual column into an array then sort them, but I am not sure how to sort more than 2 arrays. The next solution I though of was to use a datatable and organizing the columns but I am just not sure how to do.
Any ideas?
store the data in a Table inside of a dataset. If you do this then you can select all of the SQL information at once, throw it into the dataset's table and then display it in something like a datagrid.
Be sure to include for SQL:
Imports System.Data.SqlClient
Dim conn As New SqlConnection
conn.ConnectionString = "YOUR CONNECTION INFORMATION"
Dim sQuery As String = "SELECT [Number], [Name], [Date], [Date2] " & _
"FROM [YourTableName] " & _
"ORDER BY [Date]"
Dim da As New SqlDataAdapter(sQuery, conn)
Dim ds As New DataSet
Dim dt As New DataTable()
da.Fill(ds, sQuery)
dt = ds.Tables(0)
dgvYourDataGridView.DataSource = ds
dgvYourDataGridView.Refresh()
conn.Close()
conn.Dispose()
Not sure if that's what you're looking for or not.
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.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My code is not working. #X is my parameter ans ASP.NET shows error near #X parameter.
Please help.
SqlCommand cmd = new SqlCommand("SELECT top #x * FROM tblname",cn);
cmd.Parameters.AddWithValue("#x",DropDown1.SelectedItem.value);
SqlDataReader dr;
dr=cmd.executeReader();
DataList1.DataSource = dr;
DataList1.DataBind();
Just change SELECT statement this way:
SELECT top (#x) * from tblname
I only includes the brackets around #x parameter
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.