Saturday, 28 December 2013

Use Microsoft Excel Sheet as a Database in Asp.Net

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.
read an excel file

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.

Monday, 25 November 2013

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: " + x);
                Console.ReadLine();
            }
            Console.ReadLine();
        }
    }
}

IF you pass null string in  GetHostAddresses() method it will return same result as it is when pass hostname string in it. look at the following code.

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();
            string k = "";
            IPAddress [] ipaddress = Dns.GetHostAddresses(k);
            foreach (IPAddress x in ipaddress)
            {
                Console.Write("this is computer name:" + hostname + "and Ipa address is: " + x);
                Console.ReadLine();
            }
            Console.ReadLine();
        }
    }
}

Wednesday, 20 November 2013

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

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 to use in sending email

            string email = "Write Here The email ID on which you want to Receive Data";
            string name = "Email ID";
// Now mainmessage string will contain data in prescribe format in which you want
            string mainmessage = "<html><body>Name : " + TextBox1.Text + "<br />" + "Email ID: : " +     TextBox2.Text + "<br />" + "Contact No : " + TextBox3.Text + "<br />" + "Website Name : " + TextBox4.Text + "<br />" +
                "Message : " + TextBox5.Text + "<br /></body></html>";
            MailMessage msg = new MailMessage();
            msg.Subject = "Message or Feedback From a User";
            msg.Body = mainmessage;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            msg.From = new MailAddress(TextBox2.Text);
            msg.To.Add(new MailAddress(email.Trim(), name));
            SmtpClient smptc = new SmtpClient(); // Here SMTP Client object is created
            smptc.Host = "smtpout.asia.secureserver.net";// here SMTP interface Address is passed
            smptc.Port = 25;// Use port No 25
            smptc.UseDefaultCredentials = false;
            smptc.EnableSsl = false;
            smptc.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential credentials = new NetworkCredential("Write Email or User name of GoDaddy Email Account", "Password here");
            smptc.Credentials = credentials;
            smptc.Send(msg);
            Response.Write("<script type='text/javascript'>alert('Thanks! for your feedback.')</script>");
            TextBox1.Text = "";
            TextBox2.Text = "";

Hope this would help you.

Similarly you can use Gmail and Hotmail but due to some security reason they do not like such activity.

Saturday, 16 November 2013

Online Text Editor in Javascript

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.selectionStart);
            var after_txt = val.substring(Field.selectionEnd, val.length);
            Field.value = before_txt + '<'+ domofhtml +'>' + selected_txt + '</'+ domofhtml +'>' + after_txt;
       
        }
to know about list of in build function and object of java script click on this link and you would be better able to know how they are working in the above function.

here 'TextArea1' is ID of text area box in the above pic. Field store the reference of this and Val it's value and we will have to find start index of selected text and end index of this text so that we can apply our HTML tags 'domofhtml ' is parameter so that we can pass different HTML DOM through same function of click of various type buttons to edit text in TextArea.

Now on the Bold button at onclick event add this function like this

<input id="Button1" type="button" value="Bold" onclick="editor('b');" />

To make Italic text do this on italic button 

<input id="Button2" type="button"  value="Italic" onclick="editor('i');" />
 
and similarly you can add many Tags.

Thank you for giving time, Have a nice day..

Wednesday, 6 November 2013

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.

Thursday, 3 October 2013

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'.

Tuesday, 1 October 2013

URl Rewriting in Asp.net

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 employee.
when some one clicks on ID of person on FirstPage it will redirect it to SecondPage with full detail of corresponding person with user friendly URL or re written URL.
here in my code you get a method shashiurl() method with anchor tag passing two parameters to get corresponding value of name and id of a particular person. see the image.
 now in the code behind we add this method with following details (Do not forget to include Routing namespace in every pages)
 here i am passing two parameter to GetRoutUrl method which is title and id related to particular table of person and here urldatail1 is name of route which will configure in Global.asax file.
Now come to Global.asax file and write according as:
 Now in the second page, You will have to display data according to id or primary received from Firstpage.aspx. so make page according to your requirement here i am using Grid view to display data. and code behind code is as:
Here we will have to capture Route Data value so that when ever we get related URL web page can retrieve information form server.
And in code behind file customErrors mode="Off" do not forget to include it.

Thursday, 19 September 2013

Count function of SQL to count entries of various types saperately

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.

Wednesday, 18 September 2013

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 datainsertusingjquery.aspx                  
             data: "{'UserID':'" + document.getElementById('TextBox1').value + "', 'Password':'" + document.getElementById('TextBox2').value + "'}",
                    async: false,
                    success: function (response) {
                        $('#TextBox1').val('');
                        $('#TextBox2').val('');
                        alert("Record Has been Saved in Database");
                    },
                    error: function ()

                    { console.log('there is some error'); }

                });
                    });

                         });
   
   
    </script>

And in the page of 'datainserusingjquery.aspx' write this function 'InsertMethod()'
[WebMethod]
    public static string InsertMethod(string UserID, string Password)
    {
        SqlConnection con = new SqlConnection("Pass here your Data base connection string");
       
       
        SqlCommand cmd = new SqlCommand("Insert into Login values('" + UserID + "', '" + Password + "')", con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        return "True";
    }

Tuesday, 17 September 2013

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

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="Button1" runat="server" Height="33px" Text="Print"
                        Width="117px" OnClientClick="printpage()"  />

In the above javascript code Button2 is extra button in my page that's why it is in the code.

hope this will help ..

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

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 code (you can take this value in variable in the form of string.

string passedvalue= Request.QueryString["value"];
here value will carry the assigned value from one page to another. But if you are using Grid View and have link and want to display associated data on other page. Then you will have to use OnRowCommand="shashi_RowCommand" event of Grid View and corresponding command name property of link button so that various link button associated with Grid View can perform various tasks.
In my example.

here i have two link buttons in my grid view that's why used two command name so that they can perform various task associated with them. You will have to give command name in link button. see this image.


Saturday, 31 August 2013

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...

Thursday, 22 August 2013

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

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 such entry from "FirstTable".

4. Now copy "FirstTable" unique entry into "SeconTable" with the help of Sql Commands. so look at these command you can store it in your Database.
(This Blog is further extension of our previous tutorial Display RSS Feeds in Your Website & If Needed How to Store Them in DataBase ).

With the help of Two Sql Commands you can achieve such things as. (In my tables I have three Rows Common in both tables "Title", "Description", "Link" )   
Hope this will help you if not look at the full coding in picture below

 

Monday, 19 August 2013

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

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();
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 of  XmlNodeList variable 'a'.

foreach (XmlNode rssNode in a)
        {
            XmlNode rssSubNode = rssNode.SelectSingleNode("title");
            string title = rssSubNode != null ? rssSubNode.InnerText : "";
            rssSubNode = rssNode.SelectSingleNode("link");
            string link = rssSubNode != null ? rssSubNode.InnerText : "";
            rssSubNode = rssNode.SelectSingleNode("description");
            string description = rssSubNode != null ? rssSubNode.InnerText : "";
         } 

To store this in Database simply make connection and fire Sql Query with the help of variable string title, link and description. look at this snap shot in comment.
Rss Feeds in Asp.Net
 

Friday, 16 August 2013

Upload and Display YouTube Video in Asp.Net

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 contains the URL of text box in which user will enter URL of youtube video. With the help of Replace function of C# we will convert this to embedded URL and send it to database. by normal way of inserting data in database. Like this




Thursday, 8 August 2013

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

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 box in which user will give URL of YouTube videos and will click on upload like this.
You do not need to make User Name text box. On Code behind of Upload button Click write these code so that you can get Thumbnail and video converted in Embedded as well.

In the above picture it is clear that in comment you can get thumbnail of YouTube video.
Now display it in data list in horizontal direction and when some body click on that video display it in next page.
So you will need to first of all display these video in web page in our example we will display this video in same page in which we allow user to upload video for this we will take data list and code like this
we will take hep of Eval to display our Thumbnail in web page you may or may not display other things like upload date and uploaded user. we will use a method named connect_method to display video image in data list in web page.


in page load method call this function to display video links. 

Now when user click on video display this in next page. for this you will have to make a new page and take div in which you will have to define data list and a iframe inside data list tag to display video code will be like this. 

  
now that DataListItemCommand method we has declared in upload page (Look at the above data list code which display video in web page) here is that method with the help of this we will pass image "ID" in next page and display and play video in that page.

     here in Detail.aspx you should give the Url of that page in which you have declared data list and ifram to play video. and on that page you should write some code on behind page on page load event.
I tried my best to make it easy for you but if you have any doubt then you can send commend to me.

Thank you for your time at my blog..have nice day...


 
 

Saturday, 3 August 2013

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 

Wednesday, 31 July 2013

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 


 
 

 
 

Tuesday, 23 July 2013

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

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?


 <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="4" RepeatDirection="Horizontal">
     <ItemTemplate>
             <table runat="server">
                   <tr>
                       <td>
                            <iframe runat="server" src='<%#Eval("VideoLink") %>'></iframe>
                       </td>
                    </tr>
       
              </table>
       </ItemTemplate>
  </asp:DataList>


on the code behind page you can bind data list with sql data source using SQL Command.

hope this will work. thank you!...

Saturday, 6 July 2013

Check User Name And Email Already Exist without Refreshing Page

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  the same thing for second box but there you should choose appropriate column name for email ID verification. After this run your website it will show result as desired.

Hope it will work for you.

Gridview Formating Tutorail for Beginers

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 in one column there is three rows and the last row contains two columns. Now you can think that it is like defining table like these properties. So make it like as you wish. See the following code.


 <asp: TemplateField> will be under under columns section so that we can achieve our motive. In the coding part you can see that we developed various row and columns as we want very similar like defining table in HTML.

Here Eval will fetch data from database but you will have to give Sql command from Page load events or button click events. The row or columns in which you want to display data you can add Eval as shown in coding. Hope it will work for you if not then write comment if possible in will help you. 

Wednesday, 3 July 2013

MS Access as a database for storing and retrieving data



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 behind instead of SqlClient , you will have to use OleDb as namespace and all command you will give through this name space. See the code.




    8.       OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\D Rock\Documents\Innovice.accdb");
In this code you should write your own connection path for making connection string. And rest of command will go like this
            con.Open();
            OleDbCommand cmd = new OleDbCommand(“write here your Sql Quaries”);
            cmd.ExecuteNonQuery();
 


   9.      In simple way I would like to say that use OleDb instead of Sql if you are using MS Access as a database.