Archive

Archive for the ‘ASP.net C#’ Category

Log4net integration

January 13, 2017 Leave a comment

Hi folks,
I was integarting log4net library which is amazing for logging in .net Applications.

One issue i run into worth mentioning, I got following error
“log4net:ERROR Failed to find configuration section ‘log4net’ in the application’s .config file. Check your .config file for the and elements. The configuration section should look like: <section name="log4net""

When I used following declartion , issue resolved:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

Regards

Categories: ASP.net C#, Bugs, tricks

Store and Reading connection string in web.config

August 14, 2015 Leave a comment

Handy Tips for freshers:
Connection string in .NET 3.5 (and above) config file:
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.

<add name="myConnectionString" connectionString="server=\SQLEXPRESS;database=myDb;uid=myUser;password=myPass;" />

To read/access the connection string into your code, use the ConfigurationManager class.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

Always store the connection string in a config file.
I saw many freshers save connection string on page(Hard Coding) or in session, Never be among them.

Connection string in .NET 2.0 config file
In the appSettings location, add a key named whatever you like to reference your connection string to.


To read the connection string from code, use the ConfigurationSettings class.
string connStr = ConfigurationSettings.AppSettings("myConnectionString");

Hope this will help few!

Ref: https://www.connectionstrings.com/store-connection-string-in-webconfig/

Using CSS to Style a RadioButtonList Control in ASP.NET

August 13, 2015 2 comments

Hi,
I wanted to give styling to Radio list box.
Also wanted to highlight the radio span after selection.
Sharing the code for your reference:

CSS code:
.radioboxlist radioboxlistStyle
{
font-size:x-large;
padding-right: 20px;
}
.radioboxlist label {
color: #3E3928;
background-color:#E8E5D4;
padding-left: 6px;
padding-right: 16px;
padding-top: 2px;
padding-bottom: 2px;
border: 1px solid #AAAAAA;
white-space: nowrap;
clear: left;
margin-right: 10px;
margin-left: 10px;
}
.radioboxlist label:hover
{
color: #CC3300;
background: #D1CFC2;
}
input:checked + label {
color: #CC3300;
background: #D1CFC2;
}

In asp.net Server code:

<asp:RadioButtonList ID="RadioButtonListGarment" runat="server" CssClass="radioboxlist">

Categories: ASP.net C#, tricks

Cast One List to another List ASP.NET C#

June 10, 2015 Leave a comment

If We need to cast List X to List Y, We can use following syntax:

List listOfY = listOfX.Cast().ToList()

sql server 2008 – Create Schema -In just 3 steps

October 13, 2014 Leave a comment

How to create schema sql server 2008:
1. Right Click on DB in which you need to create new schema.
Then Select New Schema.

sql server 2008 - create schema

sql server 2008 – create schema

Remember: Schema is just logical concept and used for db permission and provide easy maintainability.

2. In the Schema – New dialog box, on the General page, enter a name for the new schema in the Schema name box.

3. In the Schema owner box, enter the name of a database user or role to own the schema. Alternately, click Search to open the Search Roles and Users dialog box.
In my case, its dbo.

Get Schema owner

Get Schema owner

Categories: ASP.net C#, SQL

How to find a text inside SQL Server procedures / triggers?

October 8, 2014 Leave a comment

Hi,
Today I come across an change request at my recent project:
Request was to replace a table reference to new view created in all Procedures and functions.

At first glace, I just annoyed by the change, then mu colleague has suggested a way to search though all Procedures Views and functions,

I got details from Stackoverflow.com

Code for your reference:

DECLARE @Search varchar(255)
SET @Search='TheTableNameYouareSearching'

SELECT DISTINCT
o.name AS Object_Name,o.type_desc
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id=o.object_id
WHERE m.definition Like '%'+@Search+'%'
ORDER BY 2,1

You will get all listing.Really great…Saved lot of time.

Reading MultiLine TextBox line by line from asp.net TextBox control

May 13, 2013 Leave a comment

Hi,
Today, I got a issue while reading MultiLine TextBox, and storing the content into database.
Firstly I was using TextBox.Text, which reads it all as one line.

After googling, I found nice link just sharing with you:

The Code I added is as follows:
C#
string txt = TextBox1.Text;
string[] lst = txt.Split(new Char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

VB
Dim txt As String = TextBox1.Text
Dim lst As String() = txt.Split(New [Char]() {ControlChars.Lf, ControlChars.Cr}, StringSplitOptions.RemoveEmptyEntries)

Thanx.

Categories: ASP.net C#