Can anybody tell the code to import only selected data(rows and columns) from Excel to SQL through asp.net? [closed] - sql

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 7 years ago.
Improve this question
Like here if I want to import from row 5 and column C
protected void Button1_Click(object sender, EventArgs e)
{
String csvPath = Path.Combine( Server.MapPath("~/Files/") +
Path.GetFileName(FileUpload1.PostedFile.FileName));
FileUpload1.SaveAs(csvPath);
DataTable dt = new DataTable();
dt.Columns.AddRange(
new DataColumn[3]{
new DataColumn("KPI", typeof(string)),
new DataColumn("KPIPN", typeof(string)),
new DataColumn("KPIPV", typeof(string))
});
string csvData = File.ReadAllText(csvPath);

You can use the LinqToExcel project
https://github.com/paulyoder/LinqToExcel

Related

Problem with sending mail with attachment via Admin API [closed]

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 17 days ago.
This post was edited and submitted for review 13 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
We send emails via the Admin API, with PDF attachments the PDF is then unreadable, with TXT files there is no problem.
Doku: https://shopware.stoplight.io/docs/admin-api/743f0819350c4-send-a-mail
Request-URL: _action/mail-template/send
We use the binAttachments parameter set as follows.
The "content" is fetched and without BASE64 encoding the JSON code is corrupt, if you encode it the mail can be sent. But the attachment is not valid with/without encoding.
$content = file_get_contents()
$binAttachments[] = ["content" => base64_encode($content),
"fileName" => 'test.pdf',
"mimeType" => 'application/pdf'
];
No decode is done in the API controller, here is my suggestion for change?
Adjustment of the controller
\Shopware\Core\Content\MailTemplate\Api\MailActionController
public function send(RequestDataBag $post, Context $context): JsonResponse
direkt nach der Zeile
$data = $post->all();
/optionale Decodierung des Strings, falls es ein BASE64 ist/
foreach ($data['binAttachments'] as &$binAttachment) {
if (base64_decode($binAttachment['content'], true)) {
// is valid $binAttachment['content'] = base64_decode($binAttachment['content']);
} else {
// not valid, Nothing to do
}
}
In addition, an issue has already been created:
https://issues.shopware.com/issues/NEXT-25189
Description see above

how to pass error class object as a result in API? [closed]

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 4 years ago.
Improve this question
I have create One API controller and i want to pass custom error class object as a response.
Can any one help me for that ?
Thanks in advance.
Create one class for to store error information as shown below.
ErrorInformation objError = new ErrorInformation();
try
{
test(ref Token, ref SessionToken);
}
catch (Exception ex)
{
objError.ErrorMessage = ex.Message;
objError.StatusCode = Convert.ToInt16(HttpStatusCode.ExpectationFailed);
objError.ErrorType = ex.GetType().ToString();
objError.ErrorCode = "E01";
throw new HttpResponseException(Request.CreateResponse<ErrorInformation>(HttpStatusCode.ExpectationFailed, objError));
}
This will return whole object as result.
{
"StatusCode": 417,
"ErrorMessage": "Error Detail",
"ErrorType": "System.DivideByZeroException",
"ErrorCode": "E01"
}

Hydbrid App In IBM Worklight [closed]

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
I Already done updating the password in database using SQLAdpaters in IBM Worklight Hybrid App.
I am Working on Hybrid App using IBM Worklight. I am updating user password in database using SQLAdapter, but I want to store password in encrypted format. I already have the encryption and decryption logic in java class. How can I integrate that java class with my hybrid app?
var procedure1Statement = WL.Server.createSQLStatement("UPDATE USERS SET USERPASSWORD=? WHERE USERNAME = ? AND USERPASSWORD=? ");
function updateUserPassword(newPassword,userName,password) {
return WL.Server.invokeSQLStatement({
preparedStatement : procedure1Statement,
parameters : [newPassword,userName,password]
});
}
changed code as follows
var userpwdUpdateStatement = WL.Server.createSQLStatement("UPDATE USERS SET USERPASSWORD=? WHERE USERNAME = ? AND USERPASSWORD=? ");
function updateUserPassword(newPassword,userName,password) {
var encryptdecryptutility = new com.abcd.bgf.SysCRAESencrpDecrp();
var encryptnewPassword = encryptdecryptutility.encrypt(newPassword);
var encryptoldPassword = encryptdecryptutility.encrypt(password);
return WL.Server.invokeSQLStatement({
preparedStatement : userpwdUpdateStatement,
parameters : [encryptnewPassword,userName,encryptoldPassword]
});
}

Extracting .zip files into memory at runtime (.NET) [closed]

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 9 years ago.
Improve this question
Is there a way to extract a zip file into the computer's memory at runtime (e.g. to extract a picture but put it temporarily in the memory and place it on a PictureBox)
LIBRARIES ARE ALLOWED.
I think this should work.(not tested)
Requires .net 4.5(System.IO.Compression.dll)
using System.IO.Compression;
...
byte [] pictureBuffer = null;
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (var entry in archive.Entries)
{
if(entry.FullName == "SomePicture")
{
using (zipEntryStream = entry.Open())
using (MemoryStream memStream = new MemoryStream())
{
zipEntryStream.CopyTo(memStream);
pictureBuffer = zipEntryStream.ToArray;
}
}
}
I think this should work.(not tested)
using the DotNetZip Library http://www.nuget.org/packages/DotNetZip/
using (ZipFile zip = new ZipFile(zipPath))
{
foreach (var entry in zip.Entries)
{
if(entry.FileName == "SomePicture")
{
using (var zipEntryStream = entry.OpenReader())
using (var memStream = new MemoryStream())
{
zipEntryStream.CopyTo(memStream);
pictureBuffer = zipEntryStream.ToArray;
}
}
}
}

Program to test a SQL connection string? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I need a free and quick to download program that can test a connection string.
You can make one yourself in 20sec. For example in C#
- Create a new WinForms application
- Create a new SqlConnection(connectionString)
- Exception => Bad connection string
- All ok => Good connection string
SqlConnection conn = null;
try {
conn = new SqlConnection("connection string here");
conn.Open();
// Good connection string
} catch (SqlException sqlE) {
// Bad connection string
} finally {
if (conn != null) conn.Dispose();
}
An abbreviated version of Xyphrax's answer (assuming you're running this in the debugger):
using(var conn = new SqlConnection("Connection String Here"))
conn.Open();
You can use a tinny Windows application tool: http://www.webpowersoftware.com/App/Tools/SqlServer/SqlServerConnectionTest.exe.