You can easily Add .mdf Database in ASP.NET Application.You can perform Insertion Deletion and Updation operation on Database(.mdf).You can easily deploy your ASP.NET Application on any system without any problem.If you are facing any Type of problem to Add .mdf Database then Read .
There are some steps to Add SQL Database (.mdf) in ASP.NET Website. Which are given below:
Step2:- Now open Solution Explorer-> Right mouse click on website(Application) which is as shown below:-
See it:-
Step3:- Now Double click on Database.mdf File in Solution Explorer->Now Right click on Tables Click Add New Table->Now Write required column Name-> Click save button ->Write the table NAME-> Click OK. which is as shown below :-
see it:-
Step4:- Now Double click on Submit Button -> Write the following code for Database connectivity which are given below:-
Step5:- Run the Application(Press F5).Which are shown below:
Output:-
Step6:- Now you can see the inserted data in Database.
see it:-
For More:
Click below for Download whole Application
DOWNLOAD
There are some steps to Add SQL Database (.mdf) in ASP.NET Website. Which are given below:
Step1:- First open your visual studio 2010-> go File-> click New Website->Select ASP.NET Empty website->click OK.
Go Solution Explorer->Add New web form(Default.aspx)-->Drag and drop some controls as shown below :-
see it:-
Step2:- Now open Solution Explorer-> Right mouse click on website(Application) which is as shown below:-
See it:-
Now Select SQL Server Database->click Add button ,which is shown below:-
see it:-
Step3:- Now Double click on Database.mdf File in Solution Explorer->Now Right click on Tables Click Add New Table->Now Write required column Name-> Click save button ->Write the table NAME-> Click OK. which is as shown below :-
see it:-
Step4:- Now Double click on Submit Button -> Write the following code for Database connectivity which are given below:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=RAMASHANKER-PC;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;");
con.Open();
String str = "INSERT INTO login (username,password) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand cmd = new SqlCommand(str, con);
int OBJ = Convert.ToInt32(cmd.ExecuteNonQuery());
if (OBJ > 0)
{
Label3.Text = "Data is successfully inserted in database";
}
else
{
Label3.Text = "Data is not inserted in database";
}
con.Close();
}
}
see it:-Step5:- Run the Application(Press F5).Which are shown below:
Output:-
Step6:- Now you can see the inserted data in Database.
see it:-
- Generate unique Number and save it in the database
- Make Custom Registration and Login page With Ajax in ASP.NET
- E-Post System Project
- File handling Real Application
- Make Captcha image for Asp.Net Application
- Host ASP.NET Application on Server Free
- Host Asp.Net Application on IIS Server
- Create a Setup File
- Take Print receipt in Windows Form Application
- Print the Grid Data in Windows Forms Application
Click below for Download whole Application
DOWNLOAD
Nice post :)
ReplyDeletewel thnks man, u saved me, its nw workng, i m able to do it, just need to try it in anothr project..thnks..
ReplyDeleteReally thanks
ReplyDeletethnku you so much dude...
ReplyDeleteThanks bro.
ReplyDeleteCan you explain how to add sql server db to setup file for Windows application.
@sekhar!
ReplyDeletesubscribe my site,so that you will get latest updates.I will get you latest updates wait...
thanku very much!!!!!!!!!!!!!!!!!!!!!!!!!!!!for ur tutorials....without any error icompleted the set up process.............
DeleteNice Explanation. Got lot's of new information. But i have some doubt. We did not add DB with this Setup file. Then how can we install this setup with others system??
ReplyDelete@vijaydhas c visit this link: http://www.msdotnet.co.in/2013/07/how-to-create-setup-fileexe-with.html
ReplyDeletehi dude i get an error while running the above application...the error is that
ReplyDeleteThe type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
basicaly i get an error in the..................... using System.Linq;
Remove this name space using System.Linq; then it will work fine............
DeleteHi Brother,
ReplyDeleteI like your work and am new to C# coding i have been majorly doing PHP and HTML and MySQLkindly help me with more tutorials as pdf or any thanks alot..
EMAIL : basiljereh@gmail.com
sir how i add sqlconnetion on my pc like ur above code @"Data Source=RAMASHANKER-PC;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;"
ReplyDeleteHi ALVIN Roy !
Delete1.) RAMASHANKER-PC is SQL SERVER NAME. open your sql server --> Data Source = server name ;all other things will be same if your database name= Database.mdf ,otherwise change in your connection string then it will work perfectly.
2.) If you want, where this string generated-->then follow add sql Data source on your page from toolbox--> configure it-->open below link and see step 4 then you can see this string.
http://www.msdotnet.co.in/2014/07/how-to-implement-3-tier-architecture.html#more
how to set sql connection
DeleteDB file is missing in the example
ReplyDeletethanks a ton, man. it works and i dont have to use access too.. awesome..
ReplyDeleteReally very useful
ReplyDeleteif the machine does not have installed sqlserver then it wont working I think?
ReplyDeletePlease how can I add access database MDF to my set up file
ReplyDeleteVery informative error.Thank you author for posting this kind of errors .
ReplyDeletehttp://www.wikitechy.com/fix-error/the-type-or-namespace-name-toint32-does-not-exist-in-the-namespace-convert
Both are really good.
Cheers,
Venkat
PLEASE ACCEPT OUR POST AND REPLY
ReplyDeleteWE REALLY NEED HELP
THANKS IN ADVANCE
please ask your problem ?...
Delete