Hi friends,
In my last post i shown how to search a string in database 2day i'm showing how to search a string in a table
CREATE PROCEDURE uspSearchWord @searchstring VARCHAR(100) AS
SELECT * FROM mst_country
WHERE
strcountry LIKE '%'+ @searchstring + '%'
OR
strstatus LIKE '%'+ @searchstring+'%'
ORDER BY id
where
uspSearchWord is my Store procedure Name
searchstring is word to search
mst_country Table Name
strcountry,strstatus
Have a nice day... 'N happy Coding :)
In this blog i'm posting some Asp.net,Sql Server,Jquery,HTML-5,sqlite,C#,JavaScript scripts and sample codes that i found and created by me or my friends with a mind that it Save/ Help our ass some ways...
Thursday, June 24, 2010
Wednesday, June 23, 2010
Searching Any String From A Database
Following stored procedure work as a search engine for database,i.e it will find any string from all of the table of SQL Server & returns the column names & corresponding table names where that input string/search string can be found.
USE /* Database Name*/
GO
CREATE TABLE myTable99 (TABLE_NAME sysname, COLUMN_NAME sysname, Occurs int)
GO
SET NOCOUNT ON
DECLARE @SQL varchar(8000), @TABLE_NAME sysname, @COLUMN_NAME sysname, @Sargable varchar(80), @Count int
SELECT @Sargable =/* word to be searched*/
DECLARE insaneCursor CURSOR FOR
SELECT c.TABLE_NAME, c.COLUMN_NAME
FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE c.DATA_TYPE IN ('char','nchar','varchar','nvarchar','text','ntext')
AND t.TABLE_TYPE = 'BASE TABLE'
OPEN insaneCursor
FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @SQL = 'INSERT INTO myTable99 (TABLE_NAME, COLUMN_NAME, Occurs) SELECT '
+ '''' + @TABLE_NAME + '''' + ','
+ '''' + @COLUMN_NAME + '''' + ','
+ 'COUNT(*) FROM [' + @TABLE_NAME
+ '] WHERE [' + @COLUMN_NAME + '] Like '
+ ''''+ '%' + @Sargable + '%' + ''''
--SELECT @SQL
EXEC(@SQL)
IF @@ERROR <> 0
BEGIN
SELECT @SQL
SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @TABLE_NAME
GOTO Error
END
FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME
END
SELECT * FROM myTable99 WHERE Occurs <> 0
Error:
CLOSE insaneCursor
DEALLOCATE insaneCursor
#### to drop the Table and NOCOUNT off #####
GO
DROP TABLE myTable99
GO
SET NOCOUNT OFF
Have a nice day... 'N happy Coding :)
USE /* Database Name*/
GO
CREATE TABLE myTable99 (TABLE_NAME sysname, COLUMN_NAME sysname, Occurs int)
GO
SET NOCOUNT ON
DECLARE @SQL varchar(8000), @TABLE_NAME sysname, @COLUMN_NAME sysname, @Sargable varchar(80), @Count int
SELECT @Sargable =/* word to be searched*/
DECLARE insaneCursor CURSOR FOR
SELECT c.TABLE_NAME, c.COLUMN_NAME
FROM INFORMATION_SCHEMA.Columns c INNER JOIN INFORMATION_SCHEMA.Tables t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
WHERE c.DATA_TYPE IN ('char','nchar','varchar','nvarchar','text','ntext')
AND t.TABLE_TYPE = 'BASE TABLE'
OPEN insaneCursor
FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @SQL = 'INSERT INTO myTable99 (TABLE_NAME, COLUMN_NAME, Occurs) SELECT '
+ '''' + @TABLE_NAME + '''' + ','
+ '''' + @COLUMN_NAME + '''' + ','
+ 'COUNT(*) FROM [' + @TABLE_NAME
+ '] WHERE [' + @COLUMN_NAME + '] Like '
+ ''''+ '%' + @Sargable + '%' + ''''
--SELECT @SQL
EXEC(@SQL)
IF @@ERROR <> 0
BEGIN
SELECT @SQL
SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = @TABLE_NAME
GOTO Error
END
FETCH NEXT FROM insaneCursor INTO @TABLE_NAME, @COLUMN_NAME
END
SELECT * FROM myTable99 WHERE Occurs <> 0
Error:
CLOSE insaneCursor
DEALLOCATE insaneCursor
#### to drop the Table and NOCOUNT off #####
GO
DROP TABLE myTable99
GO
SET NOCOUNT OFF
Have a nice day... 'N happy Coding :)
Monday, June 21, 2010
7 New methods to Enumerate Directory and Files in .NET 4.0
.NET 4.0 introduces 7 new methods to Enumerate directories and files. All these methods return Enumerable Collections (IEnumerable<T>), which perform better than arrays.
Here are the 7 new methods:
Directory.EnumerateDirectories - Returns an enumerable collection of directory names in a specified path
DirectoryInfo. EnumerateDirectories - Returns an enumerable collection of directory information in the current directory
Directory.EnumerateFiles - Returns an enumerable collection of file names in a specified path
DirectoryInfo.EnumerateFiles - Returns an enumerable collection of file information in the current directory
Directory. EnumerateFileSystemEntries - Returns an enumerable collection of file-system entries in a specified path
DirectoryInfo. EnumerateFileSystemInfos - Returns an enumerable collection of file system information in the current directory
File.ReadLines - Reads the lines of a file
Have a nice day... 'N happy Coding :)
Wednesday, June 2, 2010
show image from database and mouse over big image in grid
show image from database and mouse over big image in grid
demo
in my previous post i shown u how to store 'n display image from database . 2day showing u display that image in a grid as well as on mouse over the same image :)
Here I'm giving only the documentation of how to display image from database on mouse over.i got 3 js file from internet 'n I'm thanks full to them because that a very useful one i every cn. Over that js i can play video,Flash,Gif on mouse over 'n i love it
Notes
u need to call the 3 js file immediately after opening your body tag
<body>
<script type="text/javascript" src="js/wz_tooltip.js"></script>
<script type="text/javascript" src="js/tip_followscroll.js"></script>
<script type="text/javascript" src="js/tip_centerwindow.js"></script>
<script type="text/javascript" src="js/wz_tooltip.js"></script>
<script type="text/javascript" src="js/tip_followscroll.js"></script>
<script type="text/javascript" src="js/tip_centerwindow.js"></script>
'n u need to call this javascript function on the grid on asp:TemplateColumn
<asp:TemplateColumn >
<ItemTemplate>
<a href="#" onmouseover="Tip('<img src="<%# "Handler.ashx?id=" + Eval("empid") %>" />')" onmouseout="UnTip()"> <asp:Image ID="Image1" Width="150px" Height="100px" runat="server" ImageUrl ='<%# "Handler.ashx?id=" + Eval("empid") %>' /></a>
</ItemTemplate>
</asp:TemplateColumn>
<ItemTemplate>
<a href="#" onmouseover="Tip('<img src="<%# "Handler.ashx?id=" + Eval("empid") %>" />')" onmouseout="UnTip()"> <asp:Image ID="Image1" Width="150px" Height="100px" runat="server" ImageUrl ='<%# "Handler.ashx?id=" + Eval("empid") %>' /></a>
</ItemTemplate>
</asp:TemplateColumn>
Notes
Never call alt function on img control,
JavaScript is key sensitive.
'n go through my sample u will get the js file 'n necessary help from their
u can download the sample from here 'n i hope it help u
Have a nice day... 'N happy Coding :)
Tuesday, June 1, 2010
Auto complete in asp.net c# with ajax with sample
Hi ,
Today i'm showing you auto complete in asp.net with ajax.
demo
Before v start pls have a go through over this
There are some properties of AutoCompleteExtender control that handles the working of extender. AutoComplete control uses its minimum prefix length property to limit the minimum number of characters typed into the attached textbox. When user enters the characters more than the specified limit then the AutoCompleteExtender generates the list below the textbox control.
You can also enable the caching to reduce the web service calls for similar queries. There is also an option to set the number of items to be returned from the result of web service.
AutoCompleteExtender Properties
TargetControlID: ID of the Textbox control to associate it with AutoComplete Extender.
CompletionInterval: Time interval in milliseconds after which it will display the retrieved results.
CompletionSetCount: Number of items to be returned from the web service.
MinimumPrefixLength: Number of characters required to initiate the web service request.
DelimiterCharacters: Delimiter characters that can be used to separate the items in textbox. You can specify the different characters like comma, space or semi-colon. Just select the one item first time and then type separator in the textbox you will get another set of results.
FirstRowSelected: You can set that the first item of the retrieved results will be selected by default.
EnableCaching: Caching can be enabled to reduce the web service calls for the similar queries.
ServicePath: Path of the web service that will be used with AutoCompleteExtender control.
ServiceMethod: Web service method name that will return the desired result array.
CompletionListCssClass: CSS Class to change the style of dropdown that will display the generated list of results.
CompletionListItemCssClass: CSS class to change the style of list item of retrieved results.
CompletionListHighlightedItemCssClass: CSS Class to change the style of the highlighted item of the list generated by the retrieved results.
Come lets make it live.
step 1
create an aspx file and add reference of ajax to the bin folder
step 2
drag 'n drop a ajax AutoCompleteExtender to the aspx file 'n add the following code to that control.
MinimumPrefixLength="1"
DelimiterCharacters=",:"
CompletionInterval="1000"
CompletionSetCount="20"
UseContextKey="false"
ServiceMethod="GetCountryInfo"
ServicePath="WebService.asmx"
TargetControlID="TextBox1"
Animations=""
ShowOnlyCurrentWordInCompletionListItem="false"
EnableCaching="true"
FirstRowSelected="true"
DelimiterCharacters=",:"
CompletionInterval="1000"
CompletionSetCount="20"
UseContextKey="false"
ServiceMethod="GetCountryInfo"
ServicePath="WebService.asmx"
TargetControlID="TextBox1"
Animations=""
ShowOnlyCurrentWordInCompletionListItem="false"
EnableCaching="true"
FirstRowSelected="true"
step 3
add a webservice
step 4
lets move to the coding section on webservice. i create a webmethod @ their
[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 0;
string[] items = null;
DataTable dt = null;
try
{
string sql = "Select DISTINCT[strcountry] from mst_tble Where strcountry like @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "Password=****;User ID=sa;Initial Catalog=country;Data Source=localhost");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%";
dt = new DataTable();
da.Fill(dt);
count = (dt.Rows.Count == 0 ? 1 : dt.Rows.Count);
items = new string[count];
if (dt.Rows.Count == 0)
{
string v = "No match Found";
items.SetValue(v, 0);
}
else
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["strcountry"].ToString(), i);
i++;
}
}
}
catch (Exception ex)
{
}
return items;
}
public string[] GetCountryInfo(string prefixText)
{
int count = 0;
string[] items = null;
DataTable dt = null;
try
{
string sql = "Select DISTINCT[strcountry] from mst_tble Where strcountry like @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql, "Password=****;User ID=sa;Initial Catalog=country;Data Source=localhost");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%";
dt = new DataTable();
da.Fill(dt);
count = (dt.Rows.Count == 0 ? 1 : dt.Rows.Count);
items = new string[count];
if (dt.Rows.Count == 0)
{
string v = "No match Found";
items.SetValue(v, 0);
}
else
{
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["strcountry"].ToString(), i);
i++;
}
}
}
catch (Exception ex)
{
}
return items;
}
don't forgot to add this code.It will b their but it wil be commented
[System.Web.Script.Services.ScriptService]
Have a nice day... 'N happy Coding :)
Subscribe to:
Posts (Atom)