public static bool isEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
Thursday, December 16, 2010
Thursday, December 9, 2010
Monday, December 6, 2010
connectionstring
strcnn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\myDbase.mdb;uid=admin;pwd=;"
http://en.allexperts.com/q/Visual-Basic-1048/VB-MS-Access-connection-1.htm
http://www.connectionstrings.com/access-2007
http://en.allexperts.com/q/Visual-Basic-1048/VB-MS-Access-connection-1.htm
http://www.connectionstrings.com/access-2007
Sunday, December 5, 2010
get the expire date
declare @DesiredDateAtMidnight datetime = '20010709'declare @NextDateAtMidnight datetime = dateadd(day,1,@DesiredDateAtMidnight)select OrderID=h.SalesOrderID ,h.OrderDate ,h.TerritoryID ,TerritoryName=t.Name ,c.CardType ,c.CardNumber ,CardExpire=right(str(100+ExpMonth),2)+'/'+str(ExpYear,4) ,h.TotalDuefrom Sales.SalesOrderHeader hleft join Sales.SalesTerritory t on h.TerritoryID=t.TerritoryID left join Sales.CreditCard c on h.CreditCardID=c.CreditCardID where OrderDate>=@DesiredDateAtMidnight and OrderDate<@NextDateAtMidnight order by h.SalesOrderID
chk title
Int32 andindex = -1;
Int32 orindex = -1;
Int32 notindex = -1;
Int32 innerANDindex = -1;
Int32 innerORindex = -1;
Int32 innerNOTindex = -1;
if (txt.Text.Contains("AND"))
{
andindex = txt.Text.IndexOf("AND");
}
if (txt.Text.Contains("OR"))
{
orindex = txt.Text.IndexOf("OR");
}
if (txt.Text.Contains("NOT"))
{
notindex = txt.Text.IndexOf("NOT");
}
bool CHK5 = txt.Text.Contains("OR");
bool CHK6 = txt.Text.Contains("NOT");
bool CHK7 = txt.Text.Contains("AND");
if (CHK5 == false && CHK6 == false && CHK7 == false)
{
qry = "Select * from table where field Like '%" + txt.Text + "%' OR field1 Like '%" + txt.Text + "%'";
Response.Write(qry);
}
if (andindex > -1 & orindex > -1 & notindex > -1)
{
if (andindex < orindex & andindex < notindex)
{
if (orindex < notindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, orindex - innerANDindex) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, notindex - innerANDindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%'";
Response.Write(qry);
}
}
else
{
if (orindex < andindex & orindex < notindex)
{
if (andindex < notindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, notindex - innerORindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
}
}
else
{
if (notindex < andindex & notindex < orindex)
{
if (andindex < orindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(0, andindex - innerNOTindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%'OR field1 LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%'OR field1 LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
}
}
}
}
}
else
{
//--------AND CONDITION------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
bool CHK1 = txt.Text.Contains("OR");
bool CHK2 = txt.Text.Contains("NOT");
if (CHK1 == false && CHK2==false)
{
if (andindex > -1)
{
innerANDindex = andindex + 3;
string aa = txt.Text.Substring(innerANDindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (CHK2 == false)
{
if (andindex < orindex)
{
if (andindex > -1 && orindex > -1)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
string aa = txt.Text.Substring(innerANDindex);
string BB = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + BB + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + BB + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field1 LIKE '%" + BB + "%'";
Response.Write(qry);
}
}
}
if (andindex < notindex)
{
if (andindex > -1 && notindex > -1)
{
innerANDindex = andindex + 3;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, andindex - 1);
string BBA = txt.Text.Substring(innerANDindex, innerNOTindex - innerANDindex - 3);
string bbc = txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + BBA + "%' AND field1 NOT LIKE '%" + bbc + "%'";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
//--------OR CONDITION------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
if (orindex == 0)
{
}
else
{
bool chkh = txt.Text.Contains("AND");
bool chkh2 = txt.Text.Contains("NOT");
if (chkh == false && chkh2==false)
{
if (orindex > -1)
{
innerORindex = orindex + 2;
string aa = txt.Text.Substring(innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (orindex < andindex)
{
//if (orindex > -1 && orindex < -1)
//{
//}
if (andindex > -1 & orindex > -1)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
string aa = txt.Text.Substring(0, orindex - 1);
string BB = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
notindex = 0;
}
}
}
if (orindex < notindex)
{
if (orindex > -1 && notindex > -1)
{
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, orindex - 1);
string BBA = txt.Text.Substring(innerORindex, innerNOTindex - innerORindex - 3);
string bbc = txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex);
//qry = "Select * from table where field Like '%" + aaA + "%'OR field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%'OR field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%'OR field1 LIKE '%" + BBA + "%' AND field1 NOT LIKE '%" + bbc + "%' ";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
//--------NOT CONDITION------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
bool chkh1 = txt.Text.Contains("AND");
bool chkhh = txt.Text.Contains("OR");
if (notindex == 0)
{
}
if (chkh1 == false && chkhh==false)
{
if (notindex > -1)
{
innerNOTindex = notindex + 3;
string aa = txt.Text.Substring(innerNOTindex);
// qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (chkhh == false)
{
if (notindex < andindex)
{
if (notindex != 0)
{
if (notindex > -1 && andindex > -1)
{
innerANDindex = andindex + 3;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, notindex - 1);
string BBA = txt.Text.Substring(innerNOTindex, innerANDindex - innerNOTindex - 3);
string bbc = txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex);
//qry = "Select * from table where field Like '%" + aaA + "%'AND field NOT LIKE '%" + BBA + "%' AND field LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%'AND field NOT LIKE '%" + BBA + "%' AND field LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%'AND field1 NOT LIKE '%" + BBA + "%' AND field1 LIKE '%" + bbc + "%'";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
}
}
if (chkh1 == false)
{
if (notindex < orindex)
{
if (orindex > -1 && notindex > -1)
{
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, notindex - 1);
string BBA = txt.Text.Substring(innerNOTindex, orindex - innerNOTindex);
string bbc = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + aaA + "%' AND field NOT LIKE '%" + BBA + "%' OR field LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%' AND field NOT LIKE '%" + BBA + "%' OR field LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%' AND field1 NOT LIKE '%" + BBA + "%' OR field1 LIKE '%" + bbc + "%' ";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
}
}
}
Int32 orindex = -1;
Int32 notindex = -1;
Int32 innerANDindex = -1;
Int32 innerORindex = -1;
Int32 innerNOTindex = -1;
if (txt.Text.Contains("AND"))
{
andindex = txt.Text.IndexOf("AND");
}
if (txt.Text.Contains("OR"))
{
orindex = txt.Text.IndexOf("OR");
}
if (txt.Text.Contains("NOT"))
{
notindex = txt.Text.IndexOf("NOT");
}
bool CHK5 = txt.Text.Contains("OR");
bool CHK6 = txt.Text.Contains("NOT");
bool CHK7 = txt.Text.Contains("AND");
if (CHK5 == false && CHK6 == false && CHK7 == false)
{
qry = "Select * from table where field Like '%" + txt.Text + "%' OR field1 Like '%" + txt.Text + "%'";
Response.Write(qry);
}
if (andindex > -1 & orindex > -1 & notindex > -1)
{
if (andindex < orindex & andindex < notindex)
{
if (orindex < notindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, orindex - innerANDindex) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, notindex - innerANDindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%'";
Response.Write(qry);
}
}
else
{
if (orindex < andindex & orindex < notindex)
{
if (andindex < notindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, notindex - innerANDindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, notindex - innerORindex) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + txt.Text.Substring(0, notindex - innerORindex) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
}
}
else
{
if (notindex < andindex & notindex < orindex)
{
if (andindex < orindex)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, andindex - innerNOTindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(0, andindex - innerNOTindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%'OR field1 LIKE '%" + txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex) + "%'";
Response.Write(qry);
}
else
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%'OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + txt.Text.Substring(innerNOTindex, orindex - innerNOTindex) + "%'OR field1 LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
}
}
}
}
}
else
{
//--------AND CONDITION------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
bool CHK1 = txt.Text.Contains("OR");
bool CHK2 = txt.Text.Contains("NOT");
if (CHK1 == false && CHK2==false)
{
if (andindex > -1)
{
innerANDindex = andindex + 3;
string aa = txt.Text.Substring(innerANDindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (CHK2 == false)
{
if (andindex < orindex)
{
if (andindex > -1 && orindex > -1)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
string aa = txt.Text.Substring(innerANDindex);
string BB = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + BB + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field LIKE '%" + BB + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, orindex - innerANDindex) + "%' OR field1 LIKE '%" + BB + "%'";
Response.Write(qry);
}
}
}
if (andindex < notindex)
{
if (andindex > -1 && notindex > -1)
{
innerANDindex = andindex + 3;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, andindex - 1);
string BBA = txt.Text.Substring(innerANDindex, innerNOTindex - innerANDindex - 3);
string bbc = txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%' OR field1 Like '%" + txt.Text.Substring(0, andindex - 1) + "%'AND field1 LIKE '%" + BBA + "%' AND field1 NOT LIKE '%" + bbc + "%'";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
//--------OR CONDITION------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
if (orindex == 0)
{
}
else
{
bool chkh = txt.Text.Contains("AND");
bool chkh2 = txt.Text.Contains("NOT");
if (chkh == false && chkh2==false)
{
if (orindex > -1)
{
innerORindex = orindex + 2;
string aa = txt.Text.Substring(innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%'OR field1 LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (orindex < andindex)
{
//if (orindex > -1 && orindex < -1)
//{
//}
if (andindex > -1 & orindex > -1)
{
innerANDindex = andindex + 3;
innerORindex = orindex + 2;
string aa = txt.Text.Substring(0, orindex - 1);
string BB = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%' OR field1 Like '%" + txt.Text.Substring(0, orindex - 1) + "%' OR field1 LIKE '%" + txt.Text.Substring(innerORindex, andindex - innerORindex) + "%' AND field1 LIKE '%" + txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex) + "%'";
Response.Write(qry);
notindex = 0;
}
}
}
if (orindex < notindex)
{
if (orindex > -1 && notindex > -1)
{
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, orindex - 1);
string BBA = txt.Text.Substring(innerORindex, innerNOTindex - innerORindex - 3);
string bbc = txt.Text.Substring(innerNOTindex, txt.Text.Length - innerNOTindex);
//qry = "Select * from table where field Like '%" + aaA + "%'OR field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%'OR field LIKE '%" + BBA + "%' AND field NOT LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%'OR field1 LIKE '%" + BBA + "%' AND field1 NOT LIKE '%" + bbc + "%' ";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
//--------NOT CONDITION------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
bool chkh1 = txt.Text.Contains("AND");
bool chkhh = txt.Text.Contains("OR");
if (notindex == 0)
{
}
if (chkh1 == false && chkhh==false)
{
if (notindex > -1)
{
innerNOTindex = notindex + 3;
string aa = txt.Text.Substring(innerNOTindex);
// qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + aa + "%'";
qry = "Select * from table where field Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field NOT LIKE '%" + aa + "%' OR field1 Like '%" + txt.Text.Substring(0, notindex - 1) + "%'AND field1 NOT LIKE '%" + aa + "%'";
Response.Write(qry);
}
}
if (chkhh == false)
{
if (notindex < andindex)
{
if (notindex != 0)
{
if (notindex > -1 && andindex > -1)
{
innerANDindex = andindex + 3;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, notindex - 1);
string BBA = txt.Text.Substring(innerNOTindex, innerANDindex - innerNOTindex - 3);
string bbc = txt.Text.Substring(innerANDindex, txt.Text.Length - innerANDindex);
//qry = "Select * from table where field Like '%" + aaA + "%'AND field NOT LIKE '%" + BBA + "%' AND field LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%'AND field NOT LIKE '%" + BBA + "%' AND field LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%'AND field1 NOT LIKE '%" + BBA + "%' AND field1 LIKE '%" + bbc + "%'";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
}
}
if (chkh1 == false)
{
if (notindex < orindex)
{
if (orindex > -1 && notindex > -1)
{
innerORindex = orindex + 2;
innerNOTindex = notindex + 3;
string aaA = txt.Text.Substring(0, notindex - 1);
string BBA = txt.Text.Substring(innerNOTindex, orindex - innerNOTindex);
string bbc = txt.Text.Substring(innerORindex, txt.Text.Length - innerORindex);
//qry = "Select * from table where field Like '%" + aaA + "%' AND field NOT LIKE '%" + BBA + "%' OR field LIKE '%" + bbc + "%'";
qry = "Select * from table where field Like '%" + aaA + "%' AND field NOT LIKE '%" + BBA + "%' OR field LIKE '%" + bbc + "%' OR field1 Like '%" + aaA + "%' AND field1 NOT LIKE '%" + BBA + "%' OR field1 LIKE '%" + bbc + "%' ";
Response.Write(qry);
orindex = 0;
notindex = 0;
}
}
}
}
}
Monday, November 22, 2010
c++ instruction
1. http://www.codersource.net/c/c-tutorial-on-file-operations/c-file-i-o.aspx
2.http://www.syntax-example.com/Code/performs-file-read-write-update-473.aspx
2.http://www.syntax-example.com/Code/performs-file-read-write-update-473.aspx
#include <iostream.h> #include <fstream.h> #include <conio.h> staticint totrec=0; //totrec variable keep track for total variable entered//Initially Record scanned are Zerovoid main() { int choice; while(1) { clrscr(); cout<<"Choose your choice\nNOTE : one choice for one record(except viewing data)\n"; cout<<"1) Scanning intial records\n"; cout<<"2) Appending records\n"; cout<<"3) Modifying or append records\n"; cout<<"4) Viewing records\n"; cout<<"5) Exit\n"; cout<<"Enter your choice : "; cin>>choice; switch (choice) { case 1 : { ofstream outfile; outfile.open("emp",ios::out); cout<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name; outfile<<name<<endl; cout<<"Enter Age : "; int age; cin>>age; outfile<<age<<endl; cout<<"Enter programming language known by him\her : "; char lang[25]; cin>>lang; outfile<<lang<<endl; totrec= totrec + 1; outfile.close(); } break; case 2 : { ofstream outfile; outfile.open("emp",ios::app); cout<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name; outfile<<name<<endl; cout<<"Enter Age : "; int age; cin>>age; outfile<<age<<endl; cout<<"Enter programming language known by him : "; char lang[25]; cin>>lang; outfile<<lang<<endl; totrec = totrec + 1; outfile.close(); } break; case 3 : { ofstream outfile; outfile.open("emp",ios::ate); cout<<"Are you interested in adding record\nenter y or n\n"; char ans; cin>>ans; if(ans=='y' || ans=='Y') { cout<<"\n\nPlease enter the details as per demanded\n"; cout<<"\nEnter the name : "; char name[20]; cin>>name; outfile<<name<<endl; cout<<"Enter Age : "; int age; cin>>age; outfile<<age<<endl; cout<<"Enter programming language known by him : "; char lang[25]; cin>>lang; outfile<<lang<<endl; totrec = totrec + 1; } outfile.close(); } break; case 4 : { ifstream infile; infile.open("emp",ios::in); constint size=80; char line[size]; int counter=totrec; while(counter > 0) { infile.getline(line,size); cout<<"\n\nNAME : "<<line<<endl; infile.getline(line,size); cout<<"AGE : "<<line<<endl; infile.getline(line,size); cout<<"LANGUAGE : "<<line<<endl; counter--; } infile.close(); } getch(); break; case 5 : gotoout; default : cout<<"\nInvalid Choice\nTRY AGAIN\n"; } } out: }
Thursday, November 11, 2010
How To Print Part of the page in C#
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'right=50000,top=50000,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="MyFirstDiv" style="padding: 10 10 10 10; background-color: LightCyan; width: 300px;
float: left;" onclick="javascript:printPartOfPage('MyFirstDiv')">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="Div1" onclick="javascript:printPartOfPage('Div1')">
<div style="padding: 10 10 10 10; background-color: LightCyan; width: 300px; float: left;
margin-left: 50px;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="Div2" style="padding: 10 10 10 10; background-color: LightCyan; width: 300px;
float: left; margin-left: 50px;" onclick="javascript:printPartOfPage('Div2')">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var uniqueName = new Date();
var windowName = 'Print' + uniqueName.getTime();
var printWindow = window.open(windowUrl, windowName, 'right=50000,top=50000,width=0,height=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="MyFirstDiv" style="padding: 10 10 10 10; background-color: LightCyan; width: 300px;
float: left;" onclick="javascript:printPartOfPage('MyFirstDiv')">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div id="Div1" onclick="javascript:printPartOfPage('Div1')">
<div style="padding: 10 10 10 10; background-color: LightCyan; width: 300px; float: left;
margin-left: 50px;">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="Div2" style="padding: 10 10 10 10; background-color: LightCyan; width: 300px;
float: left; margin-left: 50px;" onclick="javascript:printPartOfPage('Div2')">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</form>
</body>
</html>
Sunday, November 7, 2010
check
http://www.bestfreewaredownload.com/freeware/t-free-google-translate-client-freeware-mdmcdppi.html
http://www.bestfreewaredownload.com/screenshot/improve-your-english-freeware-ykltezwx.html
http://www.bestfreewaredownload.com/screenshot/improve-your-english-freeware-ykltezwx.html
Tuesday, November 2, 2010
Fetch data from the database and place it in a marquee
1. First we should take the marquee tag in the source of our web form(Page.aspx) page like this:->
<marquee direction=”up” onmouseover=”this.start()” onmouseout=”this.stop()”
scrolldelay=”300″ style=”height: 213px”>
<asp:Literal ID=”lt1″ runat=”server”></asp:Literal></marquee>
Note:-> literal to show the database values in the marquee
2.In Database:->
My Database Name:->db2
Create a table:->
create table news1
(
id int identity(1,1),
headings varchar(50)
);
3.Page.aspx coding:->
using System.Data.SqlClient;
SqlConnection conn1 = new SqlConnection(“data source=AB\\SQLEXPRESS;initial catalog=db2;integrated security=true”);
SqlDataAdapter da1 = new SqlDataAdapter(“select * from news1″, conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, “news1″);
string s1;
s1 = “<table><tr><td><a href=Default3.aspx style=font-family: fantasy; font-size: small; font-weight:bold; font-style: normal; color: #660066>”;
s1 += ds1.Tables["news1"].Rows[0][1].ToString();
s1 += “</a></td>”;
s1 += “<br/>”;
s1 += “<tr><td><a href=Default2.aspx style=color: #9966FF; font-weight: bold;>”;
s1 += ds1.Tables["news1"].Rows[1][1].ToString();
s1 += “</a></td></table>”;
lt1.Text = s1.ToString();
<marquee direction=”up” onmouseover=”this.start()” onmouseout=”this.stop()”
scrolldelay=”300″ style=”height: 213px”>
<asp:Literal ID=”lt1″ runat=”server”></asp:Literal></marquee>
Note:-> literal to show the database values in the marquee
2.In Database:->
My Database Name:->db2
Create a table:->
create table news1
(
id int identity(1,1),
headings varchar(50)
);
3.Page.aspx coding:->
using System.Data.SqlClient;
SqlConnection conn1 = new SqlConnection(“data source=AB\\SQLEXPRESS;initial catalog=db2;integrated security=true”);
SqlDataAdapter da1 = new SqlDataAdapter(“select * from news1″, conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1, “news1″);
string s1;
s1 = “<table><tr><td><a href=Default3.aspx style=font-family: fantasy; font-size: small; font-weight:bold; font-style: normal; color: #660066>”;
s1 += ds1.Tables["news1"].Rows[0][1].ToString();
s1 += “</a></td>”;
s1 += “<br/>”;
s1 += “<tr><td><a href=Default2.aspx style=color: #9966FF; font-weight: bold;>”;
s1 += ds1.Tables["news1"].Rows[1][1].ToString();
s1 += “</a></td></table>”;
lt1.Text = s1.ToString();
CascadingDropDown in Ajax With ASP.net
Step1: Create a table in database:-
create table test
(
state1 varchar(50),
city varchar(50)
)
Step2:- In the .aspx Page:-
<select id="statelist" runat="server" onchange="showCity()" style="width: 160px">
<option></option>
</select>
<asp:DropDownList ID="citylist" runat="server" Width="184px">
</asp:DropDownList>
Take statelist for State and citylist for City
When you select any item from statelist the citylist will automatically fill because of ajax
Step3:- Write this in the <head> Part:-
<script language="JavaScript" type="text/javascript" >
var xmlHttp
var arr;
function showCity()
{
xmlHttp=GetXmlHttpObject()
var url="Default.aspx"
url=url+"?name="+document.getElementById('statelist').value
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
return false;
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var str;
str = xmlHttp.responseText;
arr=str.split(",");
var i;
for(i=0;i<arr.length;i++)
{
dd2= document.getElementById("citylist")
var theOption = new Option;
theOption.text = arr[i];
theOption.value = arr[i];
dd2.options[i] = theOption;
}
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
Step 4:- in the .cs page:-
SqlConnection con = new SqlConnection("data source = MY\\SQLEXPRESS; initial catalog = try; integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from test", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
statelist.DataSource = dr;
statelist.DataTextField = "state";
statelist.DataBind();
dr.Close();
con.Close();
}
if (Request.QueryString["name"] != null)
{
string name = Request.QueryString["name"];
Response.Clear();
con.Open();
SqlCommand cmd = new SqlCommand("select * from test where state=@state", con);
cmd.Parameters.AddWithValue("@state", name);
SqlDataReader dr;
dr = cmd.ExecuteReader();
string str = "";
int a = 0;
while (dr.Read())
{
if (a == 0)
str += dr["city"].ToString();
else
str += "," + dr["city"].ToString();
a++;
}
Response.Write(str);
Response.End();
con.Close();
}
}
create table test
(
state1 varchar(50),
city varchar(50)
)
Step2:- In the .aspx Page:-
<select id="statelist" runat="server" onchange="showCity()" style="width: 160px">
<option></option>
</select>
<asp:DropDownList ID="citylist" runat="server" Width="184px">
</asp:DropDownList>
Take statelist for State and citylist for City
When you select any item from statelist the citylist will automatically fill because of ajax
Step3:- Write this in the <head> Part:-
<script language="JavaScript" type="text/javascript" >
var xmlHttp
var arr;
function showCity()
{
xmlHttp=GetXmlHttpObject()
var url="Default.aspx"
url=url+"?name="+document.getElementById('statelist').value
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
return false;
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var str;
str = xmlHttp.responseText;
arr=str.split(",");
var i;
for(i=0;i<arr.length;i++)
{
dd2= document.getElementById("citylist")
var theOption = new Option;
theOption.text = arr[i];
theOption.value = arr[i];
dd2.options[i] = theOption;
}
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
Step 4:- in the .cs page:-
SqlConnection con = new SqlConnection("data source = MY\\SQLEXPRESS; initial catalog = try; integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from test", con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
statelist.DataSource = dr;
statelist.DataTextField = "state";
statelist.DataBind();
dr.Close();
con.Close();
}
if (Request.QueryString["name"] != null)
{
string name = Request.QueryString["name"];
Response.Clear();
con.Open();
SqlCommand cmd = new SqlCommand("select * from test where state=@state", con);
cmd.Parameters.AddWithValue("@state", name);
SqlDataReader dr;
dr = cmd.ExecuteReader();
string str = "";
int a = 0;
while (dr.Read())
{
if (a == 0)
str += dr["city"].ToString();
else
str += "," + dr["city"].ToString();
a++;
}
Response.Write(str);
Response.End();
con.Close();
}
}
Wednesday, October 27, 2010
Change color of rows in GridView on mouseover
SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlDataAdapter da1 = new SqlDataAdapter("select fname,lname,city from cust", conn1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
GridView1.DataSource = ds1;
GridView1.DataBind();
Step 2: Now we call the javascript on the Gridview on the GridView1_RowDataBound:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] =
"javascript:mouseovercolor(this);";
e.Row.Attributes["onmouseout"] =
"javascript:mouseoutcolor(this);";
}
}
Step 3: In the aspx page( call the funtion):-
<script language=javascript type="text/javascript">
function mouseovercolor(mytxt) {
mytxt.bgColor = 'Orange';
}
function mouseoutcolor(mytxt) {
element.bgColor = 'White';
}
</script>
Geographical Information by IP Address in ASP.NET and C#
There are a lot of services out there by using them we can get a Website Visitor Geographical information such as country, region, city, latitude, longitude, ZIP code, time zone and so on. It is possible just by using the IP address of website visitor's machine.
Here, in this article, I am using a service provided by http://iplocationtools.com/. This service is free and based on the IP, returns geographical data in 3 formats:
1. XML
2. JSON
3. CSV
This is the aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ip Address Location</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table cellpadding="0" cellspacing="0" width="50%" align="center" style="background-color: #f5f5f5;
color: #4f6b72;">
<tr>
<td align="center">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="panelLoc" runat="server">
<asp:TextBox ID="txtIP" runat="server"></asp:TextBox>
<asp:Button ID="btnGetLoc" runat="server" Text="Get IP Details" OnClick="btnGetLoc_Click" />
<br />
<asp:Xml ID="Xml1" runat="server"></asp:Xml>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="updProgress" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
<img alt="progress" src="images/Img.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Here is the code behind.
using System;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnGetLoc_Click(object sender, EventArgs e)
{
String url = String.Empty;
if (txtIP.Text.Trim() != String.Empty)
{
url = String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", txtIP.Text.Trim());
XDocument xDoc = XDocument.Load(url);
if (xDoc == null | xDoc.Root == null)
{
throw new ApplicationException("Data is not Valid");
}
Xml1.TransformSource = "IP.xslt";
Xml1.DocumentContent = xDoc.ToString();
}
}
}
Here, I also observe that a XML control (<asp:Xml ID="Xml1") has been added to the page.
Our XSLT will look similar to the following:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE cellspacing="4" cellpadding="4">
<xsl:for-each select="Locations/Location">
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>Ip</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="Ip"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>Status</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="Status"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>CountryCode</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="CountryCode"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>CountryName</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="CountryName"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>RegionCode</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="RegionCode"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>RegionName</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="RegionName"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>City</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="City"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>ZipPostalCode</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="ZipPostalCode"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>Latitude</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="Latitude"/>
</TD>
<TD></TD>
</TR>
<TR>
<TD width="5%" bgcolor="#3BB9FF">
<B>Longitude</B>
</TD>
<TD width="5%" valign="top" bgcolor="#48CCCD">
<xsl:value-of select="Longitude"/>
</TD>
<TD></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
When you run the application and enter an IP address, you will data something like this.
Subscribe to:
Comments (Atom)