Tuesday, June 26, 2012

Displaying "No Image" Picture when no Image is available in database



Here, You can see that how you can display the “NoImage.jpg” picture when you don’t  have any image available in database.

I am going to provide the code snippet in which you can easily handle when the imageURL is null.

Product.aspx :

<asp:DataList ID="dlProductList" runat="server"
onitemdatabound="dlProductList_ItemDataBound">
<ItemTemplate>
<asp:Image ID="imgProduct" runat="server" 
ImageUrl='<%# Bind("ProductImage") %>' />
</ItemTemplate>
</asp:DataList>


Product.aspx .cs:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
  
Protected void dlProductList_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Image imgProduct = (Image)e.Item.FindControl("imgProduct");  //find the Image
        if (String.IsNullOrEmpty(img.ImageUrl))
        {
            img.ImageUrl = "~/images/ImageNotAvailable.jpg";
        }
    }
    
Protected void BindData ()
    {
        // Replace your Credential	
        SqlConnection conn = new SqlConnection("server=VIMAL;database=DB;uid=sa;pwd=sa123");
        SqlDataAdapter da = new SqlDataAdapter("select * from test", conn);
        DataTable dt = new DataTable();
        da.Fill(dt);
       dlProductList.DataSource = dt;
       dlProductList.DataBind();
    }

I hope that it solve your problem! You can comment if you facing any issue in above. Happy coding! 

Friday, June 22, 2012

Exception : IErrorInfo.GetDescription failed with E_FAIL(0x80004005)


Issue :
Once I was try to fetch record from access database in which I have facing minor error message like :

IErrorInfo.GetDescription failed with E_FAIL(0x80004005)

Code Snippet :
Private Sub GetItems(ByVal strSearch As String)
      Try
         Dim objDAL As New DataAccessLayer

         str = "SELECT code,ProductDesc from ProductMaster where isDeleted = 0"
         str = str & " ORDER by ProductDesc"

         dtTemp = New DataTable()
         dtTemp = objDAL.GetDataTable(str, DataAccessLayer.QueryType.SelectQuery)

         If dtTemp.Rows.Count > 0 Then
           dlProductList.DataSource = dtTemp
           dlProductList.DataBind()
      Else
           lblMag.Visible = True
           lblMag.Text = "No Records Available yet."
      End If
      Catch ex As Exception
      Finally
    End Try
End Sub


Solution :

Some database field may be reserved word in several DBMS. You just replace below line in upper code :

  str = "SELECT [code],[ProductDesc ] from ProductMaster where isDeleted = 0"

you can just try with bracket like [] around the database field.

I hope that it will help you and solve your problem!

Wednesday, June 6, 2012

Connection string for Oracle, MySQL, SQLite, Excel, SQL Server and Others

In this post, i am going to discuss the little bit small things in which you can easily find out connection string with all properties for below Providers:


For Other database connectionstring, you can refer the site : http://www.connectionstrings.com

It would be useful guys! :)

PARASHURAMA JAYANTI 2020

In year 2020, Parashurama Jayanti will Celebrate on Saturday, 25th April 2020. Parashurama Jayanti Muhurat : Parashurama J...