plz explain complete step by step procedure to insert update and delete for asp.net2008 with c# and in built sql server. plz tell me where to make object & class. I am confused.
Hi Rajendra,
Always split application, logic, database interaction in different layers for e.g. 3-tier architecture(Presentation - Data Access Layer - Database). So that it is easily maintainable in future.
If you are familiar with C#, you can
> First create a basic layout of ASP.NET application i.e. Design. Be sure what you want on what event.
> Create a database containing your tables, stored procedures and functions if any
> Create a new class library project containing Data Access Logic.In *.cs file you can write C# code.. You can add new item by right click on project and then choose add new item and select Code File.
> Add reference of DAL to ASP.NET application
Syntax: (Insert using query)
public static void insertRecordinDatabase(string query)
{
if (establishConnection())
{
if (con != null)
{
try
{
cmd = con.CreateCommand(); //Create an object of sqlcommand class.
cmd.CommandText = query; //Pass command text to SqlCommand object.
cmd.CommandType = CommandType.Text; //Tell command type to text.
int rows = cmd.ExecuteNonQuery(); //Return an integer value after executing query which represents number of row affected by query.
if (rows > 0)
Console.WriteLine("Number of rows affected by query : {0}", rows);
else
Console.WriteLine("No rows affected by your query.");
}
catch
{
Console.WriteLine("Invalid query.");
}
finally
{
if (con != null)
con.Close();
}
}
}
}
If you want to insert, update delete using SQLDataSource: http://www.asp.net/data-access/tutorials/inserting-updating-and-deleting-data-with-the-sqldatasource-vb