Why are you getting connectionstring by index instead of getting them by using their name?
Mathi Mani
Posts
-
Problem with connectionstrings -
Using Image Data type for a variable is giving errorSince no code is posted, there is no way to see how you are storing and/or retrieving image. This CP article explains the steps. Please take a look. Storing and Retrieving Images from SQL Server Using Strored Procedures and C#[^]
-
Converting Array To DictionaryJust add a where clause in your code like this:
Dictionary<int, Product> productlist = products.Where(b => b != null).ToDictionary(p => p.ProductSkew, p => p);
This will ignore all the null products and convert the rest into dictionary.
-
Order by by using levels using sql ScriptLet us assume that you have following data in Employee table
Id Name Level
1 zzzz 1
2 nnnn 1
3 dddd 1
4 df 2
5 bc 2
6 za 2
7 az 2
8 ff 2
9 ef 2and these data in EmployeeRelationShip table
Id EmployeeId ManagerId
1 4 1
2 5 1
3 6 2
4 7 2
5 8 3
6 9 3This query will give results ordered by Manager Name and then by Employee Name:
select e.Name as ManagerName, b.Name as EmpName from
EmployeeRelationShip r inner join
Employee e on e.Id = r.ManagerId
inner join Employee b on b.Id = r.EmployeeId
order by e.Name, b.NameAnd the output will be:
ManagerName EmpName
dddd ff
dddd ef
nnnn za
nnnn az
zzzz df
zzzz bcHope this provides an idea for you to solve your problem.
-
Adding Objects To SessionThe issue is where you add the accts which is a List<Account> to the session. These two lines of code always replace whatever object present in
Session["acctObjects"]
accts.Add(acct);
Session["acctObjects"] = accts;To avoid the overwrite, whenever you want to add a Account to List<Account> stored in session, get the List from session, add new Account to that list and store it back to session. Here is how you can do it.
if (Session["acctObjects"] != null)
accts = (List<acct>)Session["acctObjects"];
accts.Add(acct);
Session["acctObjects"] = accts; -
Gridview with full-screen editing questionThe event you are looking for is
RowDataBound
. Add it to your gridview like this:And write your code in that event handler (gvItems_RowDataBound).
-
Nested Select queries i main select query LINQHi, Here is the link which shows how to get count from LINQ query. http://stackoverflow.com/questions/3853010/get-item-count-of-a-list-using-linq[^] Here is link that shows how to query Datatable using LINQ: Working with LINQ to Entities & LINQ to DataTable[^]
-
How to not display the a row based on a condition.If that row is not required, then filter it while getting the data from your data source. So you can avoid all these at code level in C#.
-
Trying to make a DataGridView field a color if a condition is met.Refere this question for changing the color of a grid row based on some condition. The code is in Vb.Net but you can get the idea. How Can I Change A Rows Backcolour Based On The Value In The First Cell Of The Same Row[^]
-
Trying to make a DataGridView field a color if a condition is met.When you want the row to be colored? Change the if condition based on that. It should work.
-
Trying to make a DataGridView field a color if a condition is met.May be the value ActualFTE is not greater than 1.25, as per your condition.
if (ActualFTE > 1.25) { e.Row.BackColor = Color.Red; }
So the color will not be changed.
-
Trying to make a DataGridView field a color if a condition is met.Just to make sure everything is fine, try hardcoding the value and see if you still get the error.
decimal ActualFTE=Convert.ToDecimal("0.9500");
If this works without exception, then you can be sure, the problem is with the expression
e.Row.Cells[5].Text
. This expression you use should return some string (like your value 0.9500) that can be converted to decimal for the conversion to work without exception. -
Trying to make a DataGridView field a color if a condition is met.decimal ActualFTE=Convert.ToDecimal(e.Row.Cells[5].Text);
if (ActualFTE > 1.25)In the above code check whether
e.Row.Cells[5].Text
returns data that can be converted to decimal. Or add ToString() at the end and see if it helps.decimal ActualFTE=Convert.ToDecimal(e.Row.Cells[5].Text.ToString());
-
Trying to make a DataGridView field a color if a condition is met.Can you post what value is coming in
e.Row.Cells[5].Text
It will give a better idea on what we are dealing with.
-
Trying to make a DataGridView field a color if a condition is met.The error message says it clearly. You are trying to covert a decimal to int. Change your stament like below and try.
decimal ActualFTE=Convert.ToDecimal(e.Row.Cells[5].Text);
if (ActualFTE > 1.25)