<configuration>
<appSettings>
<add key="ConnStr" value="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\MyData\App_Data\Database.mdf;Integrated Security=True;User Instance=True"/>
</appSettings>
<connectionStrings>
<add name="ConnStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\MyData\App_Data\Database.mdf;Integrated Security=True;User Instance=True"/>
</connectionStrings>
</configuration>
Monday, June 3, 2013
App setting
Sunday, June 2, 2013
Aspx for a 3 tire validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace test
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hdnSTDID.Value = "Add";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string stdName = tbxName.Text;
DBConnection dbConnection = new DBConnection();
if (hdnMode.Value == "Add")
{
string sql = "INSERT INTO Student ([Name]) VALUES ('" + stdName + "')";
dbConnection.ExecuteQuary(sql);
string script = "alert(\"ADDfgfh..!\");";
ScriptManager.RegisterStartupScript(this, this.GetType(),
"ServerControlScript", script, true);
}
if (hdnMode.Value == "Edit")
{
int stdId = int.Parse(hdnSTDID.Value);
string sqlEdite = "UPDATE Student SET Name = '" + stdName + "' WHERE StdId=" + stdId;
dbConnection.ExecuteQuary(sqlEdite);
hdnMode.Value = "Add";
btnSave.Text = "Add";
}
gvStudent.DataBind();
tbxName.Text = "";
}
protected void gvStudent_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string studentId = gvStudent.Rows[index].Cells[0].Text;
int stdID = int.Parse(studentId);
DBConnection con = new DBConnection();
if (e.CommandName == "Del")
{
string strDelete = "DELETE FROM Student WHERE StdId=" + stdID;
con.ExecuteQuary(strDelete);
gvStudent.DataBind();
}
if (e.CommandName == "Edi")
{
string sqlEdite = "SELECT StdId, Name FROM Student WHERE StdId=" + stdID;
DataSet ds = con.GetData(sqlEdite);
hdnSTDID.Value = ds.Tables[0].Rows[0]["StdId"].ToString();
tbxName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
btnSave.Text = "Edite";
hdnMode.Value = "Edit";
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace test
{
public partial class Student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hdnSTDID.Value = "Add";
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
string stdName = tbxName.Text;
DBConnection dbConnection = new DBConnection();
if (hdnMode.Value == "Add")
{
string sql = "INSERT INTO Student ([Name]) VALUES ('" + stdName + "')";
dbConnection.ExecuteQuary(sql);
string script = "alert(\"ADDfgfh..!\");";
ScriptManager.RegisterStartupScript(this, this.GetType(),
"ServerControlScript", script, true);
}
if (hdnMode.Value == "Edit")
{
int stdId = int.Parse(hdnSTDID.Value);
string sqlEdite = "UPDATE Student SET Name = '" + stdName + "' WHERE StdId=" + stdId;
dbConnection.ExecuteQuary(sqlEdite);
hdnMode.Value = "Add";
btnSave.Text = "Add";
}
gvStudent.DataBind();
tbxName.Text = "";
}
protected void gvStudent_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
string studentId = gvStudent.Rows[index].Cells[0].Text;
int stdID = int.Parse(studentId);
DBConnection con = new DBConnection();
if (e.CommandName == "Del")
{
string strDelete = "DELETE FROM Student WHERE StdId=" + stdID;
con.ExecuteQuary(strDelete);
gvStudent.DataBind();
}
if (e.CommandName == "Edi")
{
string sqlEdite = "SELECT StdId, Name FROM Student WHERE StdId=" + stdID;
DataSet ds = con.GetData(sqlEdite);
hdnSTDID.Value = ds.Tables[0].Rows[0]["StdId"].ToString();
tbxName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
btnSave.Text = "Edite";
hdnMode.Value = "Edit";
}
}
}
}
Wb.Cnfg
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<!--<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>-->
<add name="connectionStringa" connectionString="data source=LOCHANA-PC;initial catalog=StdMngSystem;user id=;password=;multipleactiveresultsets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<!--<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>-->
<add name="connectionStringa" connectionString="data source=LOCHANA-PC;initial catalog=StdMngSystem;user id=;password=;multipleactiveresultsets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
DBC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
/// <summary>
/// Summary description for DBConnection
/// </summary>
///
namespace StdMngSystem
{
public class DBConnection
{
SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionStringa"].ToString());
SqlCommand command = null;
SqlDataAdapter adapter = null;
public void ExecuteQuary(string quary)
{
try
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
command = new SqlCommand();
}
command.CommandText = quary;
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();
}
catch (Exception)
{
}
}
public DataSet GetData(string quary)
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
adapter = new SqlDataAdapter(quary, connection);
}
DataSet getDataSet = new DataSet();
adapter.Fill(getDataSet);
connection.Close();
return getDataSet;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;
/// <summary>
/// Summary description for DBConnection
/// </summary>
///
namespace StdMngSystem
{
public class DBConnection
{
SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["connectionStringa"].ToString());
SqlCommand command = null;
SqlDataAdapter adapter = null;
public void ExecuteQuary(string quary)
{
try
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
command = new SqlCommand();
}
command.CommandText = quary;
command.Connection = connection;
command.ExecuteNonQuery();
connection.Close();
}
catch (Exception)
{
}
}
public DataSet GetData(string quary)
{
if (connection.State == ConnectionState.Closed)
{
connection.Open();
adapter = new SqlDataAdapter(quary, connection);
}
DataSet getDataSet = new DataSet();
adapter.Fill(getDataSet);
connection.Close();
return getDataSet;
}
}
}
Wednesday, January 9, 2013
Read from a File Line by line JAVA
File:-
network devices.txt
10.30.12.106
10.30.11.155
10.60.100.97
192.168.50.197
10.60.100.96
10.10.5.75
10.10.5.100
10.10.5.76
192.168.1.1
10.10.5.68
code:-
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("networkdevices.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
int num = 0;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
//System.out.println (strLine);
//System.out.println ("a");
switch (num) {
case 0:
a = strLine;
break;
case 1:
b = strLine;
break;
case 2:
c = strLine;
break;
case 3:
d = strLine;
break;
case 4:
e = strLine;
break;
case 5:
f = strLine;
break;
case 6:
g = strLine;
break;
case 7:
h = strLine;
break;
case 8:
i = strLine;
break;
case 9:
k = strLine;
break;
default:
break;
}
num++;
}
//Close the input stream
in.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
note:- a,b,c,d...h are strings . should be initialize globally
:)
cheers
Subscribe to:
Comments (Atom)