web config:.
<connectionStrings>
<!-- Crm-Dev Tpl Test -->
<add name="ApplicationServicesTest" connectionString="Data Source=172.16.2.86\SQL14;Initial Catalog=TPL_Test;User Id=crmsupport;Password=swbestteam" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices" connectionString="Data Source=MNET-PC;Initial Catalog=DbTest;User Id=sa;Password=sa123" providerName="System.Data.SqlClient"/>
</connectionStrings>
---------------------------------------------------------------------------------------------
--before appsetting
public DataTable GetAllActivity()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetAllEmps", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllCity()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetCity", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllCounrty()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetCountry", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable savedata(string cityid, string countryid)
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("InsertData", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlad.SelectCommand.Parameters.AddWithValue("cityid", cityid);
sqlad.SelectCommand.Parameters.AddWithValue("countryid", countryid);
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllData()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetAlldata", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
<connectionStrings>
<!-- Crm-Dev Tpl Test -->
<add name="ApplicationServicesTest" connectionString="Data Source=172.16.2.86\SQL14;Initial Catalog=TPL_Test;User Id=crmsupport;Password=swbestteam" providerName="System.Data.SqlClient"/>
<add name="ApplicationServices" connectionString="Data Source=MNET-PC;Initial Catalog=DbTest;User Id=sa;Password=sa123" providerName="System.Data.SqlClient"/>
</connectionStrings>
--before appsetting
public DataTable GetAllActivity()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetAllEmps", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllCity()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetCity", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllCounrty()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetCountry", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable savedata(string cityid, string countryid)
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("InsertData", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlad.SelectCommand.Parameters.AddWithValue("cityid", cityid);
sqlad.SelectCommand.Parameters.AddWithValue("countryid", countryid);
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
public DataTable GetAllData()
{
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
var sqlad = new SqlDataAdapter("GetAlldata", con);
sqlad.SelectCommand.CommandType = CommandType.StoredProcedure;
var ds = new DataSet();
con.Open();
sqlad.Fill(ds);
con.Close();
return ds.Tables[0];
}
////////////////////////////////////
SQL Procedure
ALTER Procedure [dbo].[InsertData]
@cityid int,
@countryid varchar(100)
--@cityid int=2,
--@countryid varchar(100)='14,5'
As
Declare @t TABLE
(
EmployeeID INT,
Certs VARCHAR(8000)
)
INSERT @t VALUES (@cityid,@countryid)
SELECT EmployeeID,
LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Certs
into #temp FROM
(
SELECT EmployeeID,CAST('<XMLRoot><RowData>' + REPLACE(Certs,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
FROM @t
)t
CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)
Insert into tb1
select *from #temp
Select 1 as [Status],'data Has been saved' as [Message]
Drop Table #temp
SQL Procedure
ALTER Procedure [dbo].[InsertData]
@cityid int,
@countryid varchar(100)
--@cityid int=2,
--@countryid varchar(100)='14,5'
As
Declare @t TABLE
(
EmployeeID INT,
Certs VARCHAR(8000)
)
INSERT @t VALUES (@cityid,@countryid)
SELECT EmployeeID,
LTRIM(RTRIM(m.n.value('.[1]','varchar(8000)'))) AS Certs
into #temp FROM
(
SELECT EmployeeID,CAST('<XMLRoot><RowData>' + REPLACE(Certs,',','</RowData><RowData>') + '</RowData></XMLRoot>' AS XML) AS x
FROM @t
)t
CROSS APPLY x.nodes('/XMLRoot/RowData')m(n)
Insert into tb1
select *from #temp
Select 1 as [Status],'data Has been saved' as [Message]
Drop Table #temp
No comments:
Post a Comment