I'm really confused on how to go about doing this.
How I intend to do so...
Since I have my web app published on the network, hosted on my local box... my usual savepath for the file uploaded (desktop) doesn't work.
So I thought to save it onto a SQL Server that is also hosted on my local box.
Therefore, I guess I'm trying to:
Okay, that was super confusing. There must be an easier way to do this! (Do I really need a SQL database?)
Oh, and any good ideas for my savePath?
Haven't really solved this. But it's easier to read whatever's on the excel file using the OleDBConnection like this:
try
{
using (OleDbConnection olcon = new OleDbConnection())
{
olcon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(fileupFile.FileName) + ";Extended Properties=Excel 12.0";
OleDbCommand olcmd = new OleDbCommand("SELECT * FROM [Sheet1$]", olcon);
olcon.Open();
OleDbDataReader olread = olcmd.ExecuteReader();
while (olread.Read())
{
line = (String)(olread.GetString(0));
Verify(line); //calls the datatosql method
}
olcon.Close();
lblFiup.Text = "Data Inserted Sucessfully";
lblFiup.ForeColor = System.Drawing.Color.Green;
}
}
Then, pass into another method, which uses SqlConnection to write into SQL Server. Like this:
protected void datatosql(String url, String stat)
{
try
{
using (SqlConnection sqlcon = new SqlConnection("Server=(local);Database=URLs;Trusted_Connection=True"))
{
using (SqlCommand sqlcom = sqlcon.CreateCommand())
{
sqlcom.CommandText = "INSERT INTO WEVRecordsTest (URL, Status) VALUES ('" + url + "','" + stat + "')";
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
}
}
catch (SqlException se)
{
lblHist.Text = se.Message;
lblHist.ForeColor = System.Drawing.Color.Red;
}
}