Wednesday, February 15, 2012

some jquery code

jQuery(function() {

$('input#searchbox').keypress(function(event) {

if (event.keyCode == 13) {
$("#btnsearchgo").click();
}
else if (event.keyCode == 8) {
search2();
}
else {
//get text from search box + last typed letter
v = $('input#searchbox').val() + String.fromCharCode(event.charCode);

//delay the calling of the function
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 300);
$(this).data('timer', wait);

}

});

function search() {
var e = document.getElementById("ddlExchange");
var x = e.options[e.selectedIndex].value;

//alert(v);
$.getJSON("somecode.aspx?code=" + x + "&src=" + v,
function(data) {
//alert(JSON.stringify(data));
$('input#searchbox').jsonSuggest(data, { maxResults: 8, onSelect: callback });
}
);
}

});

isNumeric in C#

public static bool IsInteger(string theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
}

Friday, February 10, 2012

write to file asp.net c#

public void writeToFile(string msg)
{
string fileName = "tes.txt";
string appPath = HttpContext.Current.Request.ApplicationPath;
string physicalPath = HttpContext.Current.Request.MapPath(appPath);
fileName = Path.Combine(physicalPath, fileName);
StreamWriter writer = new StreamWriter(fileName);
writer.WriteLine(msg);
writer.Flush();
writer.Close();
}

Thursday, February 9, 2012

SQL Try Catch

BEGIN TRY
BEGIN TRANSACTION;
-- delete/insert statement here
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int;
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY();
RAISERROR(@ErrMsg, @ErrSeverity, 1);
END CATCH;

Tuesday, February 7, 2012

Primary Key in SQL for existing table

add primary key using query

ALTER TABLE dbo.tablename
ADD PRIMARY KEY (columname)

remove primary key using query

ALTER TABLE Table1
DROP CONSTRAINT [PK_Table1_Col1]