hello
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
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
Tuesday, 22 January 2013
how add connection string
</configSections>
<appSettings>
<add key="strLocalCon" value="Data Source=EASY-857AC062F0;Initial Catalog=aaa;Integrated Security=True"/>
<add key="strLocalCon1" value="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
</appSettings>
<connectionStrings>
<add name="VeePurchases" connectionString="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
<add name="VeeSale" connectionString="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
</connectionStrings>
//
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["VeePurchases"].ToString());
<appSettings>
<add key="strLocalCon" value="Data Source=EASY-857AC062F0;Initial Catalog=aaa;Integrated Security=True"/>
<add key="strLocalCon1" value="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
</appSettings>
<connectionStrings>
<add name="VeePurchases" connectionString="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
<add name="VeeSale" connectionString="Data Source=EASY-857AC062F0;Initial Catalog=aa;Integrated Security=True"/>
</connectionStrings>
//
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["VeePurchases"].ToString());
how send sms using api
protected void btnSend_Click(object
sender, EventArgs e)
{
HttpWebRequest
request = (HttpWebRequest)WebRequest.Create("http://www.sitename.in/pushsms.php?UserName=abc&Password=xyz&Type=Individual&To="
+ txtMobileNo.Text + "&Mask=S H A M
&Message=" + txtMessage.Text) as
HttpWebRequest;
HttpWebResponse
response = (HttpWebResponse)request.GetResponse();
Stream
receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader
readStream = new StreamReader(receiveStream,
encode);
string
a = readStream.ReadToEnd().ToString();
response.Close();
readStream.Close();
}
#region characters as byte array
public string UTF8ByteArrayToString(byte[]
characters)
{
UTF8Encoding encoding = new UTF8Encoding();
string
constructedString = encoding.GetString(characters);
return
constructedString;
}
#endregion
Subscribe to:
Posts (Atom)