hello
asp.net c# with sql server
asp.net c#,sql server,use sqlhelper class, funcation,class,store procedure,view,triggers,call email class in asp.net c#,MVC AND ENTITY FRAMEWORK TUTORIAL,how to create database with script using c#,datareader with sqlhelper and run time label bind in grid,insert update select storprocedure Delete duplicate record in database,Delete duplicate record in database,how add connection string,how add connection string
Thursday, 12 June 2014
Wednesday, 4 December 2013
Monday, 2 December 2013
how to create database with script using c#
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
private void CreateDatabase()
{
String str;
string constr = "Data Source=111.111.1.111;Initial Catalog=master; User Id=sa;Password=password;";
SqlConnection myConn = new SqlConnection(constr);
str = "CREATE DATABASE MyDatabase";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
string sqlConnectionString = "Data Source=111.111.1.111;Initial Catalog=MyDatabase; User Id=sa;Password=password;";
FileInfo file = new FileInfo("C:\\esage.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
}
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
private void CreateDatabase()
{
String str;
string constr = "Data Source=111.111.1.111;Initial Catalog=master; User Id=sa;Password=password;";
SqlConnection myConn = new SqlConnection(constr);
str = "CREATE DATABASE MyDatabase";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
string sqlConnectionString = "Data Source=111.111.1.111;Initial Catalog=MyDatabase; User Id=sa;Password=password;";
FileInfo file = new FileInfo("C:\\esage.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
}
}
}
Wednesday, 1 May 2013
datareader with sqlhelper and run time label bind in grid
SqlConnection con = new SqlConnection(obj.conString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SHOWDATA";
cmd.Parameters.Add("@Root", SqlDbType.Int).Value = DropDownList2.SelectedValue;
cmd.Connection = con;
try
{
con.Open();
GridView2.EmptyDataText = "No Records Found";
GridView2.DataSource = cmd.ExecuteReader();
GridView2.DataBind();
foreach (GridViewRow row in GridView2.Rows)
{
string id = ((HiddenField)row.Cells[2].FindControl("hnfID")).Value.ToString();
Label lbtsanstha = ((Label)row.Cells[2].FindControl("lblsanstah"));
SqlDataReader rdr = SqlHelper.ExecuteReader(obj.conString, CommandType.Text, "select * from SansthUserDetail where userid='" + id + "'");
while (rdr.Read())
{
string col1Value = rdr["Sanstha"].ToString();
lbtsanstha.Text = lbtsanstha.Text + ' ' + col1Value + ",".ToString();
}
lbtsanstha.Text = lbtsanstha.Text.Substring(0, lbtsanstha.Text.Length - 1);
}
}
catch (Exception ex)
{ throw ex; }
finally
{ con.Close(); con.Dispose(); }
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SHOWDATA";
cmd.Parameters.Add("@Root", SqlDbType.Int).Value = DropDownList2.SelectedValue;
cmd.Connection = con;
try
{
con.Open();
GridView2.EmptyDataText = "No Records Found";
GridView2.DataSource = cmd.ExecuteReader();
GridView2.DataBind();
foreach (GridViewRow row in GridView2.Rows)
{
string id = ((HiddenField)row.Cells[2].FindControl("hnfID")).Value.ToString();
Label lbtsanstha = ((Label)row.Cells[2].FindControl("lblsanstah"));
SqlDataReader rdr = SqlHelper.ExecuteReader(obj.conString, CommandType.Text, "select * from SansthUserDetail where userid='" + id + "'");
while (rdr.Read())
{
string col1Value = rdr["Sanstha"].ToString();
lbtsanstha.Text = lbtsanstha.Text + ' ' + col1Value + ",".ToString();
}
lbtsanstha.Text = lbtsanstha.Text.Substring(0, lbtsanstha.Text.Length - 1);
}
}
catch (Exception ex)
{ throw ex; }
finally
{ con.Close(); con.Dispose(); }
Wednesday, 24 April 2013
insert update select storprocedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[AddUpdateCustomer]
@CustomerID NCHAR(5),
@ContactName NVARCHAR(30),
@CompanyName NVARCHAR(40)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT * FROM Customers WHERE CustomerID = @CustomerID)
BEGIN
UPDATE [Customers]
SET [CompanyName] = @CompanyName
,[ContactName] = @ContactName
WHERE CustomerID = @CustomerID
END
ELSE
BEGIN
INSERT INTO [Customers]
([CustomerID]
,[CompanyName]
,[ContactName])
VALUES
(@CustomerID
,@CompanyName
,@ContactName)
END
SELECT [CustomerID]
,[CompanyName]
,[ContactName]
FROM Customers
END
Delete duplicate record in database
1:-
DELETE FROM dbo.ATTENDANCE WHERE AUTOID NOT IN (SELECT MIN(AUTOID) _
FROM dbo.ATTENDANCE GROUP BY EMPLOYEE_ID,ATTENDANCE_DATE)
2.
WITH TempUsers (FirstName,LastName, duplicateRecordCount)
AS
(
SELECT FirstName,LastName,
ROW_NUMBER()OVER(PARTITIONBY FirstName, LastName ORDERBY FirstName) AS duplicateRecordCount
FROM dbo.Users
)
DELETE
FROM TempUsers
WHERE duplicateRecordCount > 1
GO
Wednesday, 23 January 2013
n tire Architecture
http://www.mindstick.com/Articles/d36ceb0f-018c-4979-b2f5-a4a1e616cb5b/?N-Tier%20Architecture%20in%20ASP.NET
Subscribe to:
Posts (Atom)