|
There isn't anything in that which would throw an "Input string was not in a correct format" exception.
Are you sure it's not related to the markup for Repeater2 ?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Here is an example of how I am using these fields in Repeater2.
<td style="white-space: nowrap;">
Year Built:<asp:TextBox ID="boatYrBuilt" Text='<%#Eval("boatYrBuilt")%>' Style="width: 270px; margin-left: 250px;" runat="server"></asp:TextBox>
</td>
This happens only when I when I enter an account number to try to populate the form after tne records have been created.
The error does not occur when creating a new record, only when trying to pull an existing record.
|
|
|
|
|
Once again, there's nothing in the code you've shown which would produce the exception. You'll need to debug your code to find out where the exception is being thrown from.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry to keep coming back sir.
Unless, I am not debugging this correctly, when I tried debugging, it keeps breaking on Repeater1 but shows boatYrBuilt as the culprit even though it is likely to not be the issue.
In other words, I enter account number, click enter and it loads page 1 which has personal info like name, phone, address, etc.
Then as soon as I click Next (to go to page2 which is Repeater1), it throws the incorrect format string error.
Could it be these?
<ItemTemplate>
<tr>
<td>
<asp:TextBox ID="txtboatregNum" Text='<%# Eval("MarineRegNo") %>' runat="server" placeholder="Enter registration #..." Style="width: 450px;" class="form-control"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtPayerret" Text='<%# Eval("TaxPyrRetdVal") %>' runat="server" placeholder="Enter Taxpayer returned value as of Jan. 1..." Style="width: 400px;" class="form-control txtPayerret"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="cgaurdNumber" Text='<%# Eval("VesselRegNo") %>' runat="server" placeholder="Enter Coast Guard #..." Style="width: 450px;" class="form-control"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="cguardreturnedval" Text='<%# Eval("VesselTaxPyrRetdVal") %>' runat="server" placeholder="Enter Taxpayer returned value as of Jan. 1..." Style="width: 400px;" class="form-control txtPayerret"></asp:TextBox>
</td>
<td>
<asp:Button ID="BtnAdd" Style="width: 150px;" runat="server" Text="Next Boat"
OnClick="BtnAdd_Click" CssClass="btnclass" />
<asp:Button ID="btnDelete" Style="width: 120px;" runat="server" Text="Remove a row"
OnClick="btnDelete_Click" CommandArgument='<%# Container.ItemIndex %>' CssClass="btnclass" />
</td>
</tr>
</ItemTemplate>
I am just grabbing at straws now.
|
|
|
|
|
The exception will include a stack trace. There may be some framework code at the top, but as you read down it, you should eventually find something that relates to your code.
The first item which refers to your code will tell you the file and the line which triggered the exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I know you have been very patient with me and you have given me more than I asked for (Thank you) but can you please look at the below code for me?
The problem I believe, is that when I enter an account number, it is not populating the form.
Could you please see if there is something to change with the code below?
TER PROCEDURE [dbo].[sp_AllRecs]
@pin int
AS
BEGIN
SET NOCOUNT ON;
SELECT ROW_Number() OVER (ORDER BY(SELECT 0)) RowNumber, mp.[DateSold] as datesold
,mp.[SalePrice] as salePrice
,mp.[Description] as Description
,mp.[BuyerFullName] as buyername
,mp.[BuyerAddress] as buyeraddress
,mp.[BuyerCity] as buyercity
,mp.[BuyerState] as buyerstate
,mp.[BuyerZipCode] as buyerzip
,mp.[mDateSold] as mdatesold
,mp.[mSalePrice] as msalePrice
,mp.[mDescription] as mDescription
,mp.[mBuyerFullName] as mbuyername
,mp.[mBuyerAddress] as mbuyeraddress
,mp.[mBuyerCity] as mbuyercity
,mp.[mBuyerState] as mbuyerstate
,mp.[mBuyerZipCode] as mbuyerzip
,mp.[PreviousOwnerName] as PrevOnwerName
,mp.[PreviousOwnerAddress] as prevAddr
,mp.[PreviousOwnerCity] as prevCity
,mp.[PreviousOwnerState] as PrevState
,mp.[PreviousOwnerZipCode] as prevzip
,mp.[mPreviousOwnerName] as mprevOnwerName
,mp.[mPreviousOwnerAddress] as mprevAddr
,mp.[mPreviousOwnerCity] as mprevCity
,mp.[mPreviousOwnerState] as mPrevState
,mp.[mPreviousOwnerZipCode] as mprevzip
,mp.[signDate]
,mp.[sTitle]
,ms.County As boatcnty
,ms.Registration_No As aRegNo
,ms.Motor_MFG_Make AS aMake
,ms.Boat_MFG_Make as mMake
,ms.Motor_MFG_Model as ModelNoA
,ms.Boat_MFG_Model as ModelNoM
,ms.Boat_Year_Built as boatYrBuilt
,ms.Motor_Year_Built as motorYrBuilt
,ms.[Length] as blength
,ms.HullMaterial as hullmaterial
,ms.HorsePower as mhorsepower
,ISNULL(ms.HorsePowerType,'NA') as rdlmhorsepType
,ms.Boat_DatePurchased as datePurchased
,ms.Motor_DatePurchased as mdatePurchased
,ISNULL(ms.Boat_PurchaseType,'NA') as PurchaseType
,ms.Motor_PurchaseType as rblmPurchasedType
,ms.MotorCost as motorCost
,ms.BoatCost as boatCost
,ms.FileDate
,ms.boatIssues as rblIssues
,ms.motorIssues as mrblIssues
,ms.boatIssuesDetails as functionalIsses
,ms.motorIssuesDetails as mfunctionalIsses
,mf.TypeOfVessel as vesseltypeUse
,mf.VesselName as vesselname
,mf.HorspwrTypOfEngine as vesselhorsepEngine
,mf.CoastGuardNo AS coastGuardNumber
,mf.YearPurchased as VesselYrPurchased
,mf.PurchaseType as PurchasedNew
,mf.AmtOfPurchase as VesselPurchaseAmt
,mf.HomePort as homePort
,mf.WhereDocked as whereDocked
,mf.Boat_Motor_Accsry_Equip as bmequipAccessoryList
,mf.vesselLength as vessellength
,mf.YrVesselBuilt as vesselYrBult
,mf.VHullMaterial as VesselHullMateria
FROM MarineInfo m
INNER JOIN BoatMarincePurchaserInfo mp ON m.pid = mp.pid
INNER JOIN MarineScheduleD ms ON m.pid = ms.pid
INNER JOIN MarineFedVesselInfo mf ON m.pid = mf.pid
WHERE m.pid = @pin
END
C#
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;
}
}
pageLoad() event
if (!Page.IsPostBack)
{
this.getRecs(pid);
}
|
|
|
|
|
There's nothing obviously wrong with that code. Have you tried running the query in SQL Server Management Studio, to make sure you're getting the right data back?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
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
|
|
|
|
|