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);   
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.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 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">
             <table runat="server">
                            <iframe runat="server" src='<%#Eval("VideoLink") %>'></iframe>

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
            OleDbCommand cmd = new OleDbCommand(“write here your Sql Quaries”);

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