Posts

Showing posts from 2013

Use Microsoft Excel Sheet as a Database in Asp.Net

Image
To use Microsoft Excel as your database do the following stuff. 1. Open and excel sheet and create a table lets it's name be 'A' and columns names are 'ID' and 'Name' as shown in picture. Now open new project in Visual studio and add name space using System.Data; using System.Data.OleDb; using System.Data.SqlClient; Now, Make oledb connection object and pass connection string in it. But before this you should add a new folder and name it excel and paste excel sheet in this folder By this way it will be very easy for you to pass server path in connection string to get data from server. now this way you will get data. now write following code for testing purpose  The reason behind making HDR true is that we want to tell that the first line of current sheet is columns name to study more about it following the blog of Microsoft .

Get IP address and Host Name of Local Computer

In the Blog of MSDN i found and article to get host and IP address of computer I wrote a code to get it and it gives both address of IPV6 and IPV4 and we know that there is an array of type IPAddress  . and with the help of foreach it will give all address of computer and if you have virtual machine installed then it will also give IP address of this also. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace Networking {     class Program     {         static void Main( string [] args)         {             Program .gethostname();         }         public static void gethostname()         {             string hostname = Dns .GetHostName();                         IPAddress [] ipaddress = Dns .GetHostAddresses(hostname);             foreach ( IPAddress x in ipaddress)             {                 Console .Write(" this is computer name: " + hostname + " and IP address is

Send Email Through GoDaddy Server to other Email Account in Asp.net

Image
Suppose in your website you have a contact us or career page in which user may send his data or can contact you and you want that data on y our Gmail, Outlook, Hotmail or other email account. First of all look at the form In the above form if you want to receive user data on you different email accounts then one thing you should consider in your mind.  Web browser is not going to directly send data in your email account (email will be send through other email account) , So you will have to give an interface through which your server can send data from client side. So how you will do it in Asp.net ? for this you will have to go through following steps. 1. add name space                          using System.Net;                          using System.Net.Mail; 2. On click event of submit button write following code.  1. Create an object of MailMessage class like this          MailMessage msg = new MailMessage ();  in this object you will get many properties and method

Online Text Editor in Javascript

Image
here I have pic of my simply created online text editor, actually I was working on a project and it needs a form that also can edit text like making it Bold, Italic, underline and many things. So, In this smallest project I took Text area HTML DOM and few buttons as it is obvious in the above pic. When person on client side starts writing then simply he or she may need to decorate his or her writing since in database as we know that it will simply store like ordinary data and when we retrieve it it simply display it in string format. To make it decor able after saving we will have to add html tags like </br> to break line and <b></b> to make text bold. java script function code  function editor(domofhtml) {             var Field = document.getElementById('TextArea1');             var val = Field.value;             var selected_txt = val.substring(Field.selectionStart, Field.selectionEnd);             var before_txt = val.substring(0, Field.selectionSt

A Route Named 'something' Could Not Be Found in The Route Collection

This type of problem is really painful while writing code for URL Rewriting, I searched a lot on internet but could not found proper solution so i relinquished this idea but one day I was trying to rewrite URL again and suddenly got the solution for this problem. you should not worry some much about this simply upload global.asax file in root directory and this will solve your all such problem. thank you for reading this.

Error While using MySQL Database in Asp.Net

One day I tried to use MySQL database in my Asp.Net web application and when I finished all and uploaded files on server and typed URL in address bar to show the webpage function then I got an error that "MySql name space is not available, you are missing assembly reference". some thing like this. You my face such problem while doing this even you have uploaded all dll files in bin folder of your web application. The solution of such type of problem is that you should upload all contents of ' Bin ' in root. Suppose you have all web pages and dll files in bin folder in  folder named ' My_First_MySql_application ' and uploaded this in server then you will get above error. I would like to suggest you to upload your bin folder in root not in folder named ' My_First_MySql_application ' also you should not keep bin folder in folder named ' My_First_MySql_application '.

URl Rewriting in Asp.net

Image
How to write SEO or user friendly URL in asp.net? You can get complete reference regarding URL Rewriting in Asp. Net from MSDN site. actually URL rewriting means making URL user friendly so that every one can easily remember this. suppose you want to redirect user from grid view to complete detail page then you will use redirect query string then your URL would be something like this. domain.com/file_or_folder_name/parameter?id=5 . but you want to make it like this domain.com/file_or_folder_name/name_of_person/5 to do this follow these simple steps. 1. make a page name it FirstPage.aspx . and second page SecondPage.aspx 2. take a global.asax file and import name space System.Web.Routing in it. 3. make a database and enter some detail in it regarding name, sex, phone no, emp_id, and other information of several persons so that we can display them in grid view of both pages. FirstPage will contain only ID and name while SecondPage will contain full detail of emplo

Count function of SQL to count entries of various types saperately

Image
Suppose you have a table 'A' in which you have '5' or many more categories and for the same type category you have many entries. Take an example where you want to count no of employes in corresponding departments and want to display them in web page. How you will do it in Asp.Net? I did that with the help of Grid View. I took a Grid View take two columns and used following SQL Query: Select Department, Count(Name) as Emp_Name from table name group by Department having(Count(Name)>1) By this way you can easily get No of employes in corresponding departments.

Insert Data In SQL Data Base using Jquery in Asp.Net

To make you understand take a small example. Suppose we want to make a simple signup form (in which we will not check similar username or duplicate user name; I hope you can easily do it). So make a table with two columns 'UserID' and 'Password'. Take three text box one for username and other two to match and insert password (You can use java script to match password; I am not including it here). A button which will insert data in data base after clicking it. Write this code after closing form tag and just above closing of body tag. <script type="text/javascript">         $(document).ready(function () {             $("#Button1").click(function () {                 $.ajax({                     type: 'post',                     contentType: " application/json; charset=utf-8",                     url: ' datainsertunsingjquery.aspx/InsertMethod ',               // Here InsertMethod is a function on page name datains

How to Hide Buttons On Hardcopy of Printed Page and also Hide URL and Date

Image
To hide URL and date in hard copy of printed page you should do some setting in your browsers as it's setting changes according to various browsers. First look at Firefox so do it according to this. Go > Page setup > Select Margin & Header footer and make all field blank according to your requirment. In Chrome after giving print command do following If you want to hide buttons on printed page then in you javascript code you should hide all buttons after giving print command so do it as  <script type= "text/javascript" >         function printpage() {              var a = document.getElementById( "Button1" );             var b = document.getElementById( "Button2" );             a.style.visibility = 'hidden' ;             b.style.visibility = 'hidden' ;             window.print()         } </script> And in your button give command like this.. < asp:Button class=" button " ID=" Butt

Pass Value From One Web Page To Another in Asp.Net

Image
Suppose there is a scenario in which you want when you click on some text then associated value should pass to another page and with the help of this associated value you can do anything. That link my be simply in paragraph or in Grid View or in Data list. There may be many methods to do it and I hope one of them called 'Session' be in you knowledge. But doing this with help of session is not considered good so here we will use other technique as well.. Suppose you have Page 'a.aspx' and other page 'b.aspx' you want to pass value from one to another then on first page write this code but before this suppose you have a link button on click of this associated value will pass to 'b.aspx'. code on click event of link button in 'a.aspx' Response.Redirect(" b.aspx?value= " + here you should write variable of reference variable); Response.Redirect(" b.aspx "); on the page 'b.aspx' of page load event write following c

Close The Reader First Problem in Asp.net When Read Data From SQL Server

Yesterday I was trying to fetch data from SQL server with the help of SqlDataReader but I got an error message " open DataReader associated with this Command which must be closed first " I search a lot on internet and got a solution regarding this problem. It was advised by someone that when you are reading data from server and trying to insert, delete or update action with the same connection then you will face such error which will told you to close the reader first. To get the solution for this problem you should do two things. 1. Use SqlDataAdapter and Fill command when you do not want to make an other connection for insertion and other things other than read. 2. use separate sql connection for insert, delete or update action. i.e when you have a SQL Connection 'Con' for reader. Then you should use other SQL Connection for other action. Someone also advised to add MultipleActiveResultSets=Truein connection string. Hope this will help you a lot...

Delete Duplicate Entry & Update Table By Copying Data From One Table to Other

Image
Suppose you want to take regular updates from various servers and store them in your own database for any valid reason. Then you will face problem of duplicate entry in your database. To understand this suppose you want to store various RSS Feeds news for further analysis then you will automatically refresh your page in certain time interval but in such situation your database will capture various duplicate entry also. To avoid such thing happen with you you will have to manage it will proper algorithm. Okay look at this technique and i hope this will help you a lot. 1. Take Two Table named as "FirstTable" and "SecondTable". Second Table will be your main table which stores actual data without duplicate entry. First Table will store updates only. 2. With the help of some logic we first take our updates first to "FirstTable" and then we will check weather "SecondTable" has same rows or columns. 3. If it has same rows and columns then delete

Display RSS Feeds in Your Website & If Needed How to Store Them in DataBase

Image
RSS Feeds comes in the XML format and we all know that there is a start tag and other are child tag of start tag in XML format. You can read more about RSS Feeds and It's format or For simply overview you can read it from here. All the data comes in RSS Feeds like this- <rss version="2.0"> <channel>   -----   ----- <item>   ---   --- </item> </channel> </rss> to get the element inside RSS Feeds we will have to first select it's parent tag suppose..if we want title of any RSS then we will have to first select Channel tag the go to next step. like this.. XmlDocument doc = new XmlDocument (); doc.Load(" http://timesofindia.indiatimes.com/rssfeeds/1081479906.cms "); XmlNodeList a = doc.SelectNodes(" rss/channel/item ");  as from the above code it is clear that we are going to do some thing with inside the  <item></item> tag that's why we selected node with the help

Upload and Display YouTube Video in Asp.Net

Image
In this tutorial I will teach you how to upload youtube video in database and display it in various style in web page in asp.net using C#. So, here we go... Make a database table with any name as you wish and give three column 1. ID which will be primary key and will auto increase. 2. UserID user name either from session or from simple inserting name every time when upload video. 3. VideoLink for storing video link from youtube page. YouTube video will not play on you web page until you convert it in embedded video so how to check which video is embedded and which one is not. look at the image   but when a user upload or share any youtube video he or she will not upload embedded video but he or she will upload simple URL of any video so we need to convert general URL in embedded URL by this way using C#. string s = TextBox1.Text string g = " embed/ ";         string o = " watch?v= ";         string m = s.Replace(o, g);   Here string s co

Upload YouTube Video and On Video Click Display in Next Page (Similar to YouTube)

Image
if you are looking for to make a website similar to YouTube Then You are At right place. I will not tell yo to make complete web site like YouTube but will give some idea to solve particular problems like 1. How to upload YouTube Video 2. How to get Thumbnail of YouTube Video in your Database. 3. Onclick Display it in New page and Play there with some details. so here we go..... 1. how to upload video in Database.     you do not need to upload video to your database because your hosting company will not give huge data storage. So you should keep only link of that video when user upload this take link of that image. so I have link for you already above you can do it easily. Do not worry i will do it here this again. 1. First of all create a data base with some columns like this.   You do not need to make LikeCount and ViewCount because i have this for to collect like and hits on my site.Here we will store our data in server in those columns. In you Asp page create a text

Problem While Inserting Data In SQL Server In Asp.Net

Today I faced a problem while inserting data in SQL Server. The problem was that when I Click on insert button then it insert some data values in another columns while assigned columns values was correct i.e. suppose i have two columns "Name" & "Address" then Address values goes to Name column and Address column is left blank. Every thing was correct in coding not even a single line was in mistake but still this was problem for me. If you face such type of problem when you are not using SQL Stored Procedure.  Then you should use SQL Stored Procedure to insert data value because this may be problem of server or any thing else. If any body has the same problem then share your experience. thank you 

Must Declear Scalar Variable in Asp.Net Problem

This problem is very common while inserting value in database of SQL. The reason behind this is that: 1. You do not declare your SQL variable in parameters like this SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con); cmd.Parameters. AddwithValues (" Name ", TextBox1.Text);  cmd.Parameters. AddwithValues (" RollNo ", TextBox2.Text);    cmd.ExecuteNonQuery();  here you should include "@Name" and "@RollNo" with parameters 2. Second which I got is that we write cmd.ExecuteNonQuery(); above the parameter like this SqlCommand cmd= New SqlCommand(" insert into table name (Name, RollNo) values(@Name, @ RollNo",Con); cmd.ExecuteNonQuery(); cmd.Parameters. AddwithValues (" Name ", TextBox1.Text);  cmd.Parameters. AddwithValues (" RollNo ", TextBox2.Text);    This also shows Scalar variable problem. I hope this will help you a lot.  thank you   

How to Upload YouTube Video and Show it In DataListin Asp.net Using C#

Image
When you want to upload YouTube video in your server and want to display it in your web page then before this you will have to convert the YouTube link in embedded link because ifram tag of html supports this. How yo will get embedded YouTube video link. Look at the below picture. The selected text in the picture is embedded link of this video, you can get this by clicking on share text as this is obvious in picture. Since user will upload only URL got in web page you will have to convert it in embedded URL. How you will convert youtube url in embedded? if you are using C# then do link this.          string s = TextBox1.Text; // text box in which user enters Youtube URL         string g = "embed/";         string o = "watch?v=";         string m = s.Replace(o, g); // finally we get m as a embedded URL to store in database. With the help of sql command you can easily store this string m in your database. How to display these videos in aspx page?  <as

Check User Name And Email Already Exist without Refreshing Page

Image
I this tutorial i will teach you how to check username and email ID if already registered or exist in database. It will be helpful for you when you will make a user registration page. So lets start 1. first take two text boxes and two labels make sure your labels do not contain any written text (It will appear unseen while loading page) 2. make a table in your database for testing purpose right now containing two columns named 'UserName' and 'Email ID'. 3. now select username text box( textbox1) and go to source. On the left side of toolbox there is Script manager drag and drop it on your page any where in body.   4. Now, Just below Script Manager there is Update Panel (as it is seen in image) now add your textbox in this panel but you will have to add another tag named Content Template it is also in coding as shown.  5. Now double click on TextBox1 which is related to User Name  and make Sql Connection and write code as shown here.   repeat  t

Gridview Formating Tutorail for Beginers

Image
In Asp.Net gridview has its own importance because it bind same type of repeated data from server in bulk and give flexibility to programers. When I started working on gridview it was quite difficult for me to manage data in gridview because when you see other side arranging data in very stylish way and when you try to achieve it and do not succeeded in it, then it give you mental pain. But here i described some simple way to make it more understandable for you. So here we go. Suppose you want to make three columns in gridview and in one column want to set 'Tile' for your data i.e in one section Titles appear automatically. See in the above picture colored area represent different region of different data from database like Title, Description, Author Name, Date and video URL.    Do the following Steps: 1. Set The AutoGenerateColumns to Off.   It will allow you to manage your own columns in Grid View. Now you can see that there are two columns in the picture and i

MS Access as a database for storing and retrieving data

Image
Some clients prefer to use MS Access as a database for their software or web application. In this tutorial you will get a guide how to use MS Access as a database. To achieve this you should do following steps: 1.       Open MS Access.          2.       Create database by clicking on blank database.        3. Name your database on the area given. 4. Create your columns and save it. 5. Now, open your visual studio and make a new form to make software. 6. Make connection with access database as seen in image below. When you will click on add new database then a window will appear to give you comfort to add database as shown in image. This will give you connection string. when you click on create new database then to add Ms Access as a database you will have to click on change button and will have to choose database as shown in image.   Now click on brows button to find you access sheet.      7.       In the code