|
Yes, I have run it in SSMS and it displayed the correct data but geez why it is not displaying on the form is beyond me.
|
|
|
|
|
Just for my sanity, it is C# that calls the SP and references CurrentTable datatable correct?
private void getRecs(int pin)
{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("sp_AllRecs", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("@pin", pin);
cmd.Parameters.Add(p1);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dtPrevRecords = new DataTable();
sda.Fill(dtPrevRecords);
if (dtPrevRecords.Rows.Count > 0)
{
Repeater2.DataSource = dtPrevRecords;
Repeater2.DataBind();
ViewState["CurrentTable"] = dtPrevRecords;
}
}
Something should be referencing PopulateRecord method to populate those values and load them to the form and that is not happening.
|
|
|
|
|
That replaces the second table; it doesn't read anything from it.
The PopulateRecord method is called from OnClickNext , so long as certain conditions have been met:
protected void OnClickNext(object sender, EventArgs e)
{
DataTable dt = LoadTable1(false);
if (dt != null)
{
...
myMultiView.ActiveViewIndex += 1;
if (myMultiView.ActiveViewIndex != 3)
{
PopulateRecord(dt);
}
}
}
Those conditions are the same as in the code you posted[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry, I am going to stop bothering you after this question.
You have given me more than enough of your time and assistance.
So, as far as the OnClickNext() method is concerned, the only conditions that have to be met are that those four form fields have values which they do.
Am I missing some other conditions that have to be met from that method?
modified 9-Oct-17 11:11am.
|
|
|
|
|
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?
|
|
|
|