|
Eddie's right about the code smell of the try with an empty catch . Use int.TryParse to determine if there's a parsing error.
If value.Value is an empty string then the parsing will fail.
(Since you aren't getting a NullReferenceException on the .ToString() it means that value.Value isn't null .)
So what you should do first is to check value.Value for being empty.
public static tbl_Location ParseLocation(IOrderedDictionary values)
{
tbl_Location locFromValues = new tbl_Location();
Type locType = typeof(tbl_Location);
foreach (DictionaryEntry value in values)
{
string key = value.Key as string;
if (key == null)
throw new InvalidOperationException(string.Format("Key is not a string: {0}", value.Key);
string val = value.Value as string;
bool emptyValue = string.IsNullOrEmpty(val);
object storableValue = null;
if (key.Equals("Latitude") || key.Equals("Longitude"))
{
double parsed;
if (!emptyValue && double.TryParse(val, out parsed))
storableValue = parsed;
}
else if (key.Contains("ID"))
{
int parsed;
if (!emptyValue && int.TryParse(val, out parsed))
storableValue = parsed;
}
else
{
storableValue = val;
}
locType.GetProperty(key).SetValue(locFromValues, storableValue);
}
return locFromValues;
}
All of a sudden you mention TextBox .
The TextBox's .Text property expects a string value.
So where is the value from the PostID property of the tbl_Location get put into this TextBox 's .Text property you mention?
That is probably where the "null" from "parsing" the empty string gets displayed.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Sorry for the late reply, but thank you both for your help. There is more to it than this from what I investigate. However, I have replaced the empty catch block with the if else TryParse. It is cleaner and better. What this is supposed to do is retrieve matching data from gridviewOne and gridviewTwo, and displaying results in gridviewResults with a new ID. The db is returning the ID to the BLL class (above), but it does not return all the way to the view forms. So the actual error has been resolved, but a prior change (undocumented) occurred where an ID was overridden so the next error I generate is object null reference error. My CO brought me in to fix the bug because no one knows what happened. But I appreciate your assistance and I will gladly post for more help as you guys are the best! Keep up the good work!
|
|
|
|
|
I am getting error in the bold line. i have column name as paword but its showing column name doesnt belong to the table
public Userdetails GetUserDetailsByEmailID(String EmailID)
{
Userdetails userInfobyEmailID = null;
NpgsqlParameter[] parameters = new NpgsqlParameter[] {
new NpgsqlParameter("@email", EmailID)
};
using (DataTable table = Helper.ExecuteParamerizedSelectCommand("forgetpassword", CommandType.StoredProcedure, parameters))
{
if (table.Rows.Count > 0)
{
userInfobyEmailID = new Userdetails();
foreach (DataRow row in table.Rows)
{
userInfobyEmailID.paword = Utilities.Decrypt(row["paword"].ToString());
}
}
return userInfobyEmailID;
}
}
|
|
|
|
|
Are you certain that is the correct spelling of the column name?
|
|
|
|
|
no in table also name is same
|
|
|
|
|
I find that hard to believe. Show the exact details of what gets posted into your DataTable from the stored procedure.
|
|
|
|
|
Also, please do not post the same question in a forum and QA.
|
|
|
|
|
Did you miss all those replies to your last question where we suggested you read up on how to securely handle passwords in your application? Or did you just choose to ignore them?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The passwords are well hidden in a field with unknown name...
|
|
|
|
|
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Dear All,
I want to buy Data Access Layer component for my project.
Anyone could give me advise.
Thanks,
LVD
|
|
|
|
|
levanduyet_vn wrote: I want to buy Sorry, this is not an online shopping site.
|
|
|
|
|
Hi Richard,
I just want to get help from expert and get their advise.
|
|
|
|
|
levanduyet_vn wrote: I just want to get help Then you need to explain what your problem is.
|
|
|
|
|
levanduyet_vn wrote: I want to buy Data Access Layer component for my project. Why? There are many free ones available and it's incredibly trivial to write your own DAL.
This space for rent
|
|
|
|
|
Dear Pete,
Please give me the links that I could refer.
Thanks,
LVD
|
|
|
|
|
In the time you took to write that, you could have used Google[^] to find examples. There's a CP one there that shows a simple DAL.
This space for rent
|
|
|
|
|
Hi Pete,
Sure, I have google but I need to have a advise from who have used it.
LVD
|
|
|
|
|
maybe this one[^] works for you?
It is very simple and quick to use. It is also very stable.
It might be limited in possibilities, but using the code you can extend as much as you want.
Hope this helps.
|
|
|
|
|
|
Use Entity Framework and its free, this is just a abstracted data layer.
<tag>I have no tag
|
|
|
|
|
Dear All,
I have tried to amend existing connection string from file App.config and save it back.
The code as following:
<pre lang="c#">
const string DEFAULT_CONNECTION_KEY = "defaultConnection";
ConnectionStringsSection section = (ConnectionStringsSection)config.GetSection("connectionStrings");
sConName = ConfigurationManager.AppSettings[DEFAULT_CONNECTION_KEY];
config.ConnectionStrings.ConnectionStrings[sConName].ConnectionString = sConCrypt;
config.Save(ConfigurationSaveMode.Full, true);
ConfigurationManager.RefreshSection("connectionStrings");
But it show an error.
"An error occurred creating the configuration section handle for log4net: Could not load file or assembly 'log4net' or one of its dependencies. The system cannot find the file specified.
F:\...\bin\Debug\PuFoamControl.vshost.exe.Config line 4"
Anyone can help me.
Thanks,
LVD
|
|
|
|
|
That means that your app.config contains a section for configuring log4net, but the log4net dll is not present in the folder or in the GAC. Make sure it is available, or remove the log4net specific sections manually from your app.config.
|
|
|
|
|
Thank you Hiller.
I delete this section and it run ok.
LVD
|
|
|
|
|
Hi!
I've a bi-dimensional array of labels (a lot of them) so when I make change properties the render is to slow.
My solution (I thought) was make the panel invisible at the init time and then visible when the job is completed but it's visible before the job is completed! I think my app is multithreaded for default.
using System;
using System.Windows.Forms;
namespace Program
{
public partial class Form1 : Form
{
MySqlConnection cn = new MySqlConnection();
iTextSharp.text.pdf.PdfWriter writer;
const int panelHeight = 730;
const int panelWith = 1070;
private Label[,] lbs = new Label[70,50];
public Form1()
{
InitializeComponent();
initBoard();
}
private void initBoard()
{
panel1.Size = new Size(panelWith, panelHeight);
panel1.Visible = false;
anel1.BackColor = SystemColors.ControlText;
int cc, ff;
for (int c = 0; c < 70; c++)
{
cc = c * 15;
for (int f = 0; f < 50; f++)
{
ff = f * 20;
Label lb = new Label();
lbs[c, f] = lb;
lb.Size = new Size(15, 20);
lb.Font = new System.Drawing.Font(label1.Font.Name, 12, FontStyle.Bold);
lb.Location = new System.Drawing.Point(cc + 10, ff + 10);
lb.Parent = panel1;
lb.ForeColor = Color.WhiteSmoke;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int c = 0; c < 70; c++)
for (int f = 0; f < 50; f++)
lbs[c, f].Text = (f % 10).ToString();
panel1.Visible = true;
}
}
}
Any ideas ?
Of course I'm just starting.... this is not the way I should program
modified 29-Feb-16 12:27pm.
|
|
|
|