Could not find stored procedure 'sp_sdidebug'.
Might get this error message when debugging in VS 2003.
Need to uncheck the Microsoft T SQL when attaching the Debugger from the processes window to aspnet
Error usually appears when you are manually attaching the debugger
Bobby
Wednesday, November 3, 2010
Thursday, October 28, 2010
upload file to a database
Following is code to read a file from html Input and convert it into byte[]
Following is the code to insert in DB
Thanks,
Suman
byte[] imgBinaryData = null; try { Stream imgStream = UploadFile.PostedFile.InputStream; int imgLen = UploadFile.PostedFile.ContentLength; imgBinaryData = new byte[imgLen]; int n = imgStream.Read(imgBinaryData, 0, imgLen); imgStream .Dispose (); } catch (Exception) { }
Following is the code to insert in DB
string cmdtext1 = "INSERT INTO [Info]([ID] ,[Picture],[afterpic]) values(1,@pic,@aftpic)"; SqlConnection scn = new SqlConnection(AppContext.ConnectionString); SqlCommand scmd = new SqlCommand(cmdtext1, scn); SqlParameter param1 = new SqlParameter("@pic", SqlDbType.Image); SqlParameter param2 = new SqlParameter("@aftpic", SqlDbType.Image); param1.Value = imgBinaryData; param2.Value = imgBinaryData1; scmd.Parameters.Add(param1); scmd.Parameters.Add(param2); scn.Open(); scmd.ExecuteNonQuery(); scn.Close(); imgBinaryData=null;; imgBinaryData1=null;
Thanks,
Suman
Wednesday, October 27, 2010
xml xslt issue with html tags
If you print a dataset to a xml and if one of the values of a XML node has html tags they will be converted
for ex a "<" will be converted to a "<" etc... when using style sheet to convert the XML use the following in XSL to
disable-output-escaping="yes"
<xsl:value-of select="img1" disable-output-escaping="yes" />
Suman
Thursday, October 21, 2010
read excel sheet C#
Assuming txtFileName is a textbox which has the name of the excel. Make sure the sheet name is Sheet1. Please adjust the code according to your requirements.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtFileName .Text .ToString () + ";Extended Properties=Excel 8.0;"; OleDbConnection oleDBConn = new OleDbConnection(sConnectionString); oleDBConn.Open(); OleDbCommand oleDBCmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oleDBConn); OleDbDataAdapter oledbadptr = new OleDbDataAdapter(); oledbadptr.SelectCommand = oleDBCmd; DataSet ds1 = new DataSet(); oledbadptr.Fill(ds1); oleDBConn.Close();
Friday, October 15, 2010
Useful Code
Save stream to a file in C#
public static void saveFile(Stream stream, string FileName) { if (stream.Length == 0) return; // Create a FileStream object to write a stream to a file using (FileStream fileStream = System.IO.File.Create(FileName, (int)stream.Length)) { // Fill the bytes[] array with the stream data byte[] bytesInStream = new byte[stream.Length]; stream.Read(bytesInStream, 0, (int)bytesInStream.Length); // Use FileStream object to write to the specified file fileStream.Write(bytesInStream, 0, bytesInStream.Length); } }
Tuesday, September 21, 2010
isDbNULL with Datarow in .NET
You want to check for isdbnull while using datarow from a datatable/dataset this is how you use it..
C# CODE:
Assuming orow is the datarow you are working with ...
if (!Convert.IsDBNull(orow [5]))
{
// Do some thing
}
else
{
//Do some thing else...
}
Thanks,
Suman
C# CODE:
Assuming orow is the datarow you are working with ...
if (!Convert.IsDBNull(orow [5]))
{
// Do some thing
}
else
{
//Do some thing else...
}
Thanks,
Suman
Monday, May 24, 2010
Row Index on button click in a gridview
Find the Row index when you click a button in a gridview by using the following in the button click method in code behind
GridViewRow row = ((LinkButton)sender).Parent.Parent as GridViewRow;
Response.Write(row.RowIndex);
Other way to use it is to have a command Name(for ex:View) and a Command Argument for the button and then using the GridView_RowCommand(object sender, GridViewCommandEventArgs e) _
There you can use some thing like
if (e.CommandName.ToString().Equals("View"))
{
int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
}
GridViewRow row = ((LinkButton)sender).Parent.Parent as GridViewRow;
Response.Write(row.RowIndex);
Other way to use it is to have a command Name(for ex:View) and a Command Argument for the button and then using the GridView_RowCommand(object sender, GridViewCommandEventArgs e) _
There you can use some thing like
if (e.CommandName.ToString().Equals("View"))
{
int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
}
Labels:
button,
Command,
command Argument,
gridview,
index,
row index,
rowcommand
Thursday, May 20, 2010
VS 2005 takes too much time to load
VS 2005 takes too much time to load when you open it or trying to open a project.
Go to Tools -- > Import and Export Settings
and select Reset Settings.
That should do it.
You can do it as often as you want
Go to Tools -- > Import and Export Settings
and select Reset Settings.
That should do it.
You can do it as often as you want
Friday, April 9, 2010
Force the users to download rather than opening
For known content types like PDF, doc, mp3 etc..... when you have a download link it just opens it in the browser if the browser knows how to open..
If you want to force the user to download rather than being opened / played in web browser do the following with asp.net
Create a link using a link button and on button click do the following
string myFilename="../docs/abc.doc";
Response.AppendHeader( "content-disposition", "attachment; filename=" + myFilename );
The 2 lines above would force the browser to show the download box .
Hope this Helps.
Bobby
If you want to force the user to download rather than being opened / played in web browser do the following with asp.net
Create a link using a link button and on button click do the following
string myFilename="../docs/abc.doc";
Response.AppendHeader( "content-disposition", "attachment; filename=" + myFilename );
The 2 lines above would force the browser to show the download box .
Hope this Helps.
Bobby
Labels:
.NET,
ajax,
AppendHeader,
asp,
asp.net,
attachment,
Browser,
C#,
C#.NET,
Content Download,
content Type,
Content-disposition,
finename,
HTML,
Response,
Web apps
Wednesday, March 10, 2010
Keyboard quits working in visual studio 2005
For Some reason Unknown (Or known only to microsoft) some times the keyboard would quit working on VS 2005.
Re installation might help some times and some times it wont.
Looks like when you click on Design to switch to Design mode you will lose the Key board .
Here is a link for the Fix that i found which fixes it
http://petesbloggerama.blogspot.com/2006/07/internet-explorer-7-beta-3-and-loss-of.html
Thanks,
Bobby
Re installation might help some times and some times it wont.
Looks like when you click on Design to switch to Design mode you will lose the Key board .
Here is a link for the Fix that i found which fixes it
http://petesbloggerama.blogspot.com/2006/07/internet-explorer-7-beta-3-and-loss-of.html
Thanks,
Bobby
Labels:
asp,
asp.net,
C#,
C#.NET,
functionality,
key board doesnt work,
keyboard,
microsoft,
visual studio 2005,
vs 2005
Monday, February 22, 2010
Inject javascript in Head Section using asp.net
Even though it doesn't matter where the script is in the form or in the head section, you want to have it in the HEAD section of the HTML.
When you use Page.RegisterClientScriptBlock it injects the script in the body.
To inject in the HEAD section do the following...
When you use Page.RegisterClientScriptBlock it injects the script in the body.
To inject in the HEAD section do the following...
HtmlGenericControl myScriptCode = new HtmlGenericControl("script"); myScriptCode.Attributes.Add("type", "text/javascript"); myScriptCode.InnerHtml = "alert('Alert generated by Script in Head Section of HTML');"; this.Page.Header.Controls.Add(myScriptCode);that should do it.check it by clicking view source and you should see the Script in HEAD section If you want to refer to a js file as a external file use the SRC attribute
string jssrc="../abc.js"; HtmlGenericControl myScriptCode = new HtmlGenericControl("script"); myScriptCode.Attributes.Add("type", "text/javascript"); myScriptCode.Attributes.Add("src",jssrc); this.Page.Header.Controls.Add(myScriptCode);
Labels:
.NET,
asp,
asp.net,
C#,
C#.NET,
dotnet,
FORM,
HEAD,
HTML,
inject,
javascript,
javascript from code behind,
javascript in head section,
programming,
SCRIPT,
software
Subscribe to:
Posts (Atom)