Hello, I am trying to upload a file from exel to a database / SQL SERVER 2008 through AJAX . But I have a problem with the file when I send the data ... at this moment I have not managed to mount the file in the query to execute it, on the contrary the error that ajax sends is that of the file, I can not send it myself. I would greatly appreciate your help :)
I do not have any errors in the console or in the browser more than this, I suppose maybe I should try the file or something to upload it.
<form id="uploadForm">
<div class="container">
<div class=row "">
<div class="col-lg-6">
<table class="table table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nombre</td>
<td>
<input type="text" placeholder="NombreDeProyecto" id="name" />
</td>
</tr>
<tr>
<td>Formato</td>
<td>
<label>Formato: </label> <input type="file" id="format" />
</td>
</tr>
<tr>
<td>Wiw</td>
<td>
<p>
@Session["Wiw"]
<input type="text" class="hidden" id="wiw" value="@Session[" WiW "]" />
</p>
</td>
</tr>
<tr>
<td>
<input type="button" onclick="tryx()" name="name" value="trymeplz" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-6"></div>
</div>
</form>
</div>
<script>
function tryx() {
var form = new FormData($("#uploadForm")[0]);
$.ajax({
url: '@Url.Action("KyoTest", "Home")',
method: "POST",
dataType: 'json',
data: form,
processData: false,
contentType: false,
success: function(result) {
alert("at least Ajax looks fine" + response);
},
error: function(er) {
alert("something got wrong" + er);
}
});
}
</script>
[HttpPost]
public ActionResult KyoTest(testsoru form) {
string constr = "Data Source=DMX87025;Initial Catalog=DB_PCC;Integrated Security=True";
using(SqlConnection con = new SqlConnection(constr)) {
string query = "INSERT INTO Testsoru([Name],[Wiw],[Formato],[Size],[FName],[Type])" +
" VALUES(@Name,@wiw,@format,@Size,@FName,@Type)";
using(SqlCommand cmd = new SqlCommand(query, con)) {
cmd.Parameters.AddWithValue("@Name", form.name);
cmd.Parameters.AddWithValue("@wiw", form.wiw);
cmd.Parameters.AddWithValue("@format", form.formato);
cmd.Parameters.AddWithValue("@Size", DBNull.Value);
cmd.Parameters.AddWithValue("@FName", DBNull.Value);
cmd.Parameters.AddWithValue("@Type", DBNull.Value);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
return View(form);
}
//