|
The two conditions which need to be met are:
- The first table (
CurrTable ) exists - ie: something has called LoadTable1(true) before OnClickNext is called; and myMultiView.ActiveViewIndex is not equal to 2 at the start of the method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<pre>using System;
using System.ServiceProcess;
using System.Data.SqlClient;
using System.IO;
using System.Timers;
using System.Configuration;
using System.Data.OleDb;
using System.Data;
namespace MoveToDesiredDest
{
public partial class Service1 : ServiceBase
{
long delay = 5000;
protected string LogPath = ConfigurationManager.AppSettings["LogPath"];
protected string MoveFilePathPath = ConfigurationManager.AppSettings["MovePath"];
public Service1()
{
InitializeComponent();
Timer timer1 = new Timer();
timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer1.Interval = delay;
timer1.Enabled = true;
timer1.Start();
}
protected override void OnStart(string[] args)
{
WriteLog("Service started");
if (!Directory.Exists(LogPath))
{
Directory.CreateDirectory(LogPath);
}
try
{
delay = Int32.Parse(ConfigurationManager.AppSettings["IntervalInSeconds"]) * 1000;
}
catch
{
WriteLog("IntervalInSeconds key/value incorrect.");
}
if (delay < 5000)
{
WriteLog("Sleep time too short: Changed to default(5 secs).");
delay = 5000;
}
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
write();
Upload();
}
private void write()
{
string sourcepath = ConfigurationManager.AppSettings["sourcepath"];
WriteLog("Set source path");
string[] sourcefiles = Directory.GetFiles(sourcepath);
WriteLog("Get soutce path file");
foreach (string childfile in sourcefiles)
{
WriteLog("Start to find file from loop");
string sourceFileName = new FileInfo(childfile).Name;
string destinationPath = ConfigurationManager.AppSettings["destinationPath"];
string destinationFileName = sourceFileName;
string sourceFile = Path.Combine(sourcepath, sourceFileName);
WriteLog("Get file from source to destination");
string destinationFile = Path.Combine(destinationPath, destinationFileName);
WriteLog("Ready to copy");
File.Copy(sourceFile, destinationFile, true);
WriteLog("File copied");
File.Delete(sourceFile);
WriteLog("File deleted");
}
}
protected void Upload()
{
string excelPath = ConfigurationManager.AppSettings["ExcelPath"];
DirectoryInfo d = new DirectoryInfo(excelPath);
FileInfo[] Files = d.GetFiles("*.xls");
string str = "";
WriteLog("ready to enter into loop");
foreach (FileInfo file in Files)
{
str = file.Name;
string sourceFilePath = ConfigurationManager.AppSettings["SourceFilePath"];
string SourceFileName = Path.Combine(sourceFilePath, str);
string destinationFilePath = ConfigurationManager.AppSettings["MovePath"];
string destinationFileName = destinationFilePath + str;
WriteLog("get file :" + str);
String strConnection = ConfigurationManager.AppSettings["constr"];
WriteLog("declare database connection");
string path = excelPath + str;
string excelConnectionString = @"Microsoft.Jet.OLEDB.4.0;Data Source=" + path +";Extended Properties=Excel 8.0;HDR =YES;Persist Security Info=False";
WriteLog("declare excel oledb connection");
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name] from [Sheet1$]", excelConnection);
excelConnection.Open();
WriteLog("oledb open");
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
sqlBulk.DestinationTableName = "Test1";
WriteLog("ready to insert into database");
sqlBulk.WriteToServer(dReader);
WriteLog("data inserted");
excelConnection.Close();
WriteLog("Process completed");
File.Move(SourceFileName, destinationFileName);
WriteLog("File moved to bak folder");
excelConnection.Close();
cmd.Dispose();
}
}
protected override void OnStop()
{
WriteLog("service stopped");
}
protected void WriteLog(string Msg)
{
FileStream fs = new FileStream(LogPath + "\\" + System.DateTime.Today.ToString("yyyyMMdd") + ".log", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(System.DateTime.Now.ToString() + ": " + Msg);
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
}
}
|
|
|
|
|
Nor should it. That code does not target SQL server; it uses OleDb to target the excel files in a directory.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks for the quote buddy......... i think you miss something, the connection string i declared that was in Appconfig .... '
strConnection ' and you doesn't even wanted to know where is my connection string for SQL.......?? but you commented on me. good. Please check the code properly.. And another thing please don't give the free Quote without judgement. Thanks
|
|
|
|
|
Man, I'm just trying to help you out, but if you really want me to address your passive-aggressive BS:
Member 12863453 wrote: string excelConnectionString = @"Microsoft.Jet.OLEDB.4.0;Data Source=" + path +";Extended Properties=Excel 8.0;HDR =YES;Persist Security Info=False";
That's a hard-set connection string, not being pulled from AppConfig. The only part being set in appConfig is the machine path for the directory where the files are stored. You can set a connectionString in AppConfig all day and it literally doesn't matter if you don't use it.
Member 12863453 wrote: OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
That's a class that uses the OLEDB provider to connect. That's meant for Office products, not SQL Server. It MIGHT work with SQL Server if the Client Tools Connectivity pack is installed on said server instance, but there's literally no point in using it when you have the native driver available (namely, SqlConnection).
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks buddy ,
I Solved it..................
I didn't know there is a joke like you exists.....
I don't even change my code for a single word......
Actually you don't even know .... what i was talking about....???
But the best part is you starting to comment on it..... Isn't it a joke.......??????
Is was a windows service which can move file to desire destination and insert data into sql server in my desired table......
So don't comment in a conversion if you are not able to understand it....
Here is the code for you...
Please run it with VS 2015 and then install the service and check it.........
<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;
using System.Timers;
using System.Configuration;
using System.Data.OleDb;
namespace MoveToDest
{
public partial class Service1 : ServiceBase
{
long delay = 5000;
protected string LogPath = ConfigurationManager.AppSettings["LogPath"];
protected string MoveFilePathPath = ConfigurationManager.AppSettings["MovePath"];
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
WriteLog("Service started");
if (!Directory.Exists(LogPath))
{
Directory.CreateDirectory(LogPath);
}
try
{
delay = Int32.Parse(ConfigurationManager.AppSettings["IntervalInSeconds"]) * 1000;
}
catch
{
WriteLog("IntervalInSeconds key/value incorrect.");
}
if (delay < 5000)
{
WriteLog("Sleep time too short: Changed to default(5 secs).");
delay = 5000;
}
Timer timer1 = new Timer();
timer1.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer1.Interval = delay;
timer1.Enabled = true;
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
write();
Upload();
}
private void write()
{
string sourcepath = ConfigurationManager.AppSettings["sourcepath"];
WriteLog("Set source path");
string[] sourcefiles = Directory.GetFiles(sourcepath);
WriteLog("Get soutce path file");
foreach (string childfile in sourcefiles)
{
WriteLog("Start to find file from loop");
string sourceFileName = new FileInfo(childfile).Name;
string destinationPath = ConfigurationManager.AppSettings["destinationPath"];
string destinationFileName = sourceFileName;
string sourceFile = Path.Combine(sourcepath, sourceFileName);
WriteLog("Get file from source to destination");
string destinationFile = Path.Combine(destinationPath, destinationFileName);
WriteLog("Ready to copy");
File.Copy(sourceFile, destinationFile, true);
WriteLog("File copied");
File.Delete(sourceFile);
WriteLog("File deleted");
}
}
protected void Upload()
{
string excelPath = ConfigurationManager.AppSettings["ExcelPath"];
DirectoryInfo d = new DirectoryInfo(excelPath);
FileInfo[] Files = d.GetFiles("*.xlsx");
string str = "";
WriteLog("ready to enter into loop");
foreach (FileInfo file in Files)
{
str = file.Name;
string sourceFilePath = ConfigurationManager.AppSettings["SourceFilePath"];
string SourceFileName = Path.Combine(sourceFilePath, str);
string destinationFilePath = ConfigurationManager.AppSettings["MovePath"];
string destinationFileName = destinationFilePath + str;
WriteLog("get file :" + str);
String strConnection = ConfigurationManager.AppSettings["constr"];
WriteLog("declare database connection");
string path = excelPath + str;
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
WriteLog("declare excel oledb connection");
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name] from [Sheet1$]", excelConnection);
excelConnection.Open();
WriteLog("oledb open");
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
sqlBulk.DestinationTableName = "shrabon";
WriteLog("ready to insert into database");
sqlBulk.WriteToServer(dReader);
WriteLog("data inserted");
excelConnection.Close();
WriteLog("Process completed");
File.Move(SourceFileName, destinationFileName);
WriteLog("File moved to bak folder");
excelConnection.Close();
cmd.Dispose();
}
}
protected void WriteLog(string Msg)
{
FileStream fs = new FileStream(LogPath + "\\" + System.DateTime.Today.ToString("yyyyMMdd") + ".log", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine(System.DateTime.Now.ToString() + ": " + Msg);
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}
protected override void OnStop()
{
WriteLog("service stopped");
}
}
}
And the AppConfig is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="IntervalInSeconds" value="5"/>
<add key="sourcepath" value="F:\shrabon"/>
<add key="destinationPath" value="E:\Test"/>
<add key="ExcelPath" value="E:\Test\"/>
<add key="LogPath" value="E:\Floralog"/>
<add key="MovePath" value="E:\Test\bak\"/>
<add key="SourceFilePath" value="E:\Test"/>
<add key="constr" value="Data Source=.;Initial Catalog=zam;User ID=eftuser;Password=eftuser321"/>
</appSettings>
</configuration>
Thanks for Showing off... But Now i know What you are
|
|
|
|
|
Have you used your debugger to check that your dReader actually returns some rows?
And why have you posted this here and not in the Database forum?
|
|
|
|
|
Yes I debug it ... and it stuck in
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
here as infinity loop .
|
|
|
|
|
That makes no sense, where is the loop on that statement?
|
|
|
|
|
Sorry i think i failed to present you the issue..... actually it stuck in there and don't forward to next statement. and go back to the previous method "Upload". So that i told the loop thing. actually there was no loop in that statement. but during this process the service not stopped even once but it continuously repeat the statements
thanks
|
|
|
|
|
Well there is something deeply wrong with your project, but there is no way anyone here can debug it for you. I can only suggest doing a complete rebuild and trying to get more debug information.
|
|
|
|
|
I will look for it
Thanks Buddy for your suggestions
|
|
|
|
|
Thank you so much for your help..... I solved it...
|
|
|
|
|
I have this RadioButtonList in Repeater control.
We are using Repeater control dynamically add new rows. I seem to handle projects where rows are dynamically added
In any case, when a record is added for the first time for just one row, there are no issues with this line of code:
<asp:RadioButtonList ID="rdlmhorsepType" Text='<%#string.IsNullOrEmpty((string)Eval("rdlmhorsepType")) ? "Recoil" : Eval("rdlmhorsepType") %>' runat="server" ValidationGroup ="stype" RepeatDirection="Horizontal" TextAlign="Right" style="display:inline;">
However, when one row is filled with data and another row is added, I run into the following error messages:
able to cast object of type 'System.DBNull' to type 'System.String'.
While I am at this, is there a way to populate dynamically populated dropdownlist in Repeater?
I have this:
<asp:DropDownList ID="ddlPrevState" cssClass="disabledcss" runat="server" AppendDataBoundItems="True">
<asp:ListItem Value="" Selected="True"></asp:ListItem>
</asp:DropDownList>
Here is C# code:
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ppmtest"].ToString());
string sSQL = "Select sID,sName from states ORDER By sName ASC";
SqlCommand cmd3 = new SqlCommand(sSQL, con);
con.Open();
cstable = new DataTable();
cstable.Load(cmd3.ExecuteReader());
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var ddlPState = (DropDownList)e.Item.FindControl("ddlPrevState");
ddlPState.DataSource = cstable;
ddlPState.DataTextField = "sName";
ddlPState.DataValueField = "sID";
ddlPState.DataBind();
Any ideas how to resolve this?
Thanks as always
|
|
|
|
|
Try something like this:
Text='<%# Eval("rdlmhorsepType", "{0}") ?? "Recoil" %>'
Or alternatively:
Text='<%# string.IsNullOrEmpty(Eval("rdlmhorsepType", "{0}")) ? "Recoil" : Eval("rdlmhorsepType", "{0}") %>'
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much sir.
The alternative option worked for me.
Thanks a lot for your help.
|
|
|
|
|
Hi,
I created a website in Dot Net Core 1.1.
If I am deploying my site on domain directly all static files are getting loaded and my website is running fine but as I am deploying my website in sub domain, none of the static file(css, fonts, js) is getting loaded.
Really appreciate your help in advance.
|
|
|
|
|
googled first but do not find any suitable one. so looking for a details article on repository and data access code in dotnet core unit testing
where we will not use any 3rd part library like mock or effort rather use anything built-in.
anything exist such like ?
can we unit test repository and data access code with intellitrace ? share idea. thanks
|
|
|
|
|
First of all I'd ask why you don't want to use a mocking framework, it'll make your life a lot easier. However if you don't want to use one then you can use a technique called self-shunting. That is where the test class itself acts as the mocked object and you can write any code you want in your "mocked" methods.
In this brief example I have a ProductService class that uses an IProductRepository to access the products. There's only a simply Get method but it gives you the rough idea. So in my unit test I make the test class implement IProductRepository and I mock the Get method in the test class itself.
public interface IProductRepository
{
Product Get(int id);
void Add(Product product);
}
public class ProductService : IProductService
{
private IProductRepository productRepository;
public ProductService(IProductRepository productRepository)
{
this.productRepository = productRepository;
}
public Product GetProduct(int id)
{
return this.productRepository.Get(id);
}
}
Unit test
[TestClass]
public class ProductServiceTests : IProductRepository
{
private Product Product { get; set; }
[TestMethod]
public void WhenValidGetProductIsCalledProductIsReturned()
{
this.Product = new Product { ID = 1, Name = "Test product" };
ProductService ps = new ProductService(this);
Product p = ps.GetProduct(1);
Assert.AreSame(this.Product, p);
}
[TestMethod]
public void WhenInvalidGetProductIsCalledProductIsReturned()
{
this.Product = new Product { ID = 1, Name = "Test product" };
ProductService ps = new ProductService(this);
Product p = ps.GetProduct(2);
Assert.IsNull(p);
}
public void Add(Product product)
{
throw new NotImplementedException();
}
public Product Get(int id)
{
if (this.Product.ID == id)
{
return this.Product;
}
else
{
return null;
}
}
}
|
|
|
|
|
thank you so much for giving me some idea.
|
|
|
|
|
I just started to be assigned a work station that was low on memory so I accidently removed the wrong version of the .net framework. To correct the problem, I downloaded .net framework 4.0 since that is what the application uses. This web form application uses vb.net 2010 visual studio ide.
I problem is I probably downloaded the wrong version. The application probably was using a version number 4.3 I am guessing.
Thus I am trying to determine what I need to do to solve the problem.
Here is where the steps of where the problem lies:
'retarget the project to .net framework 4.0. After the project opens, you can retarget the
1. When I try to debug the application, I get the following error message:
”Retarget the project to .net framework 4.0.
Once I see the above message, I just click the OK button. I do not know where to point the application.
2. After that point I get lots of messages that look like the following:
AttendanceLetters\App_Code\mylistbox.vb(1): Build (web): Reference assemblies for target .NET Framework version not found; please ensure they are installed, or select a valid target version.
Thus to solve the problem can you tell me the following:
1. Can you tell me and/or point to a url (link) that will solve the problem tell me how and/or how to point the application to the correct target link?
2. If that is not possible, do I need to download some version of the .net framework that the application is expecting to see? If so, how can I tell what version the application is looking for?
3. If the above solutions do not work. should I uninstall the visual studio 2010 that is on this workstation and reinstall a new version so that the application can find the correct version of the .net framework?
4. If you have a different solution would you tell me what I should do to solve the problem?
|
|
|
|
|
Hello All!
Not sure if this is the correct forum to ask this, so if not, please let me know and I will have it changed.
I have created an API for my website that Godaddy hosts on a dedicated server. I have Wordpress installed and it's on a Linux server. I created the API in Visual Studio 2015 Community and ran tests on my local PC and it works as expected. Now, I need to put it online so I can test. I am planning on having it in my WPF desktop program that when the user clicks a button it will call the API and return the result. This API will check a database to see if the license code is there and if not already used. Currently, I have static code that will return a value and not connected to the database yet.
My question: Where on my website do I put files and what files go on the website? Also, how do I find out what the actual URL will be for my button click to call the API?
Thank you in advance
modified 14-Sep-17 17:24pm.
|
|
|
|
|
Greetings again.
I have this:
sp:RadioButtonList ID="rdlmhorsepType" Text='<%#Eval("horsepType").ToString()%>' runat="server" ValidationGroup ="stype" RepeatDirection="Horizontal" TextAlign="Right" style="display:inline;" AutoPostBack="true" OnSelectedIndexChanged="horsepType_SelectedIndexChanged">
<asp:ListItem Text="Electric" />
<asp:ListItem Text="Recoil" />
</asp:RadioButtonList><br />
When a user enters his/her account number, if there is data associated with that account number, it populates a repeater form.
This part works fine.
The issue is that if no data is associated with that account number, I get the following error:
'horsepType' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
In other words, if RadioButtonList is null, it throws that error.
I have several of those on my Repeater control.
Any ideas how to resolve this?
Thanks a lot in advance
|
|
|
|
|
When you are building a list its items have two parts - text and value, text for display and value to select.
If you are building your list from database you have to decide how values are build, you can use the text as value too in which case text must be unique. If you want to use a text-value pair, you must ensure value is not null (which means that in this case the database must have proper values) - there is no other way, so you must choose...
If you can not change the way the data is, you must filter out those have no value or create a fallback, which uses the text in case value is null..
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Let me try to explain this one more time, hopefully better.
We have a lookup table with a list of account numbers.
For a user to fill his/her account information, s/he must first select an account from the look up table.
When that account number is entered, if any records associated with that account exists, then those records populate the Repeater control form.
Users can then either modify any existing record or enter any records that does not exist already exist with that account number.
So, in my situation, if any of those values on the RadioButtonList does not exist, then it throws the error it is throwing now.
This is not a question of inserting null value in RadioButtonList because it is a required field.
It is a question of no value existing at all and user needs to be allowed to choose of the two values but the user cannot get to that point of selecting a value when the error message doesn't let them get there.
I believe this datatable below is the source of the error.
If I can figure out a way to assign it a default value other than empty string, I think it will resolve the issue.
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["horsepType"] = string.Empty;
dr["rblIssues"] = string.Empty;
dr["vesseltypeUse"] = string.Empty;
dt.Rows.Add(dr);
}
else
{
dt = (DataTable)ViewState["CurrentTable"];
}
ViewState["CurrentTable"] = dt;
if (dt.Rows.Count > 0)
{
Repeater2.DataSource = dt;
Repeater2.DataBind();
}
}
|
|
|
|