Sunday, January 10, 2016

Data Compare and Update using SQL Server Database Project

Synchronizing two database is a common scenario but the task sometimes take so much time and effort to synchronize two databases perfectly. Some developers maintain script to sync the databases and runs those script time to time. I found it works well but maintain the script properly is a difficult job if more than one developer works in a single database. In this blog post we will discuss how we can sync two databases using SQL Server Database Project, its advantages and disadvantages.

Sunday, October 18, 2015

Redshift: Upload Data to Redshift from SQL Server using Python Script

Download Executable Attachment

Sometimes we need to upload data to Redshift from SQL Server. But there is no straightforward way to do that. And we have to do the following task manually to import the data to redshift.
  1. Export data from SQL Server to a text file.
  2. Compressed the file to GZIP.
  3. Upload the file to S3.
  4. Execute copy command in redshift.

Wednesday, September 9, 2015

SSIS: Perform upsert (Update/Insert) using SSIS Package

It is a common scenario, when we need a script, package or something else to perform insert and update in a table simultaneously. Sometimes the task seems easy and sometimes it takes so much time to perfectly synchronize the databases. In this blog post we will try to create a SSIS package that performs the synchronization task by performing upsert (Insert/Update) using SSIS lookup transformation.

Saturday, August 8, 2015

Traditional (Row-Oriented) Database Vs Columnar Database

What is the real difference of columnar database over traditional (row-oriented) database? 

Columnar database is a database system that stores data in a column-wise fashion while in traditional database data has stored in row-wise fashion. Let’s see an example so that we can visualize how data will be stored for these two approaches. Below image shows our example record set.

Tuesday, July 14, 2015

Redshift: How to alter column datatype in redshift

There is no direct way to change the column datatype in redshift. If we want to change the column name we can use redshift alter statement with rename keyword like,

alter table BDPlayers rename column category to grade;

Thursday, July 2, 2015

Redshift: Store and Querying JSON object in Redshift

Problem: How to store JSON objects in redshift and also apply filter, group by, order by etc on that object?

Solution: Suppose we have a sparse table, where we need to add many columns and it could be exceed the maximum column limit supported by redshift. In that situation we can store the data for a row in key:value pairs in a single JSON string. JSON uses UTF-8 encoded text string so we can store JSON string in redshift text or varchar type column. For demonstration purpose we have created a table and insert some dummy JSON object. Below is the script.

Thursday, June 18, 2015

Redshift: Some Interesting behaviour of Redshift Query

I have found some interesting behaviour of redshift query. It is interesting in a sense that the query runs perfectly in redshift but not in other database (SQL Server or PostgreSQL). Let’s see the behaviour. First one describes in http://www.sqlhaven.com/interesting-aggregate-query-result-using-clause-redshift/ this blog post by brother Khorshed Alam.


Sunday, June 7, 2015

SSIS: Excel Import 255 character Truncation issue and Solution

Few days ago we have created a SSIS package to load excel data in our SQL Server database. When we run the package for a sample excel file, it runs perfectly. But when we run the package for original excel file it fails.


Sunday, May 31, 2015

How to Create, Deploy and Configure SSIS Package: Part 1



Data loading from various source is a common task for data centric application. SSIS package is a very handy and easy to learn tools to load data from various source like excel, flat file or other database. In this SQL Server Integration Service(SSIS) series we try to learn, how to create, deploy, configure and monitor SSIS package. In first article of the series we will create a simple SSIS package which extract data from excel file then load the data to a SQL server database.


Initial Setup

Before we do anything else, we need to create necessary table to which we want to load data from the excel file. Lets create the.

CREATE TABLE DataLoadTest
(
       Id int IDENTITY(1,1) PRIMARY KEY,
       Name nvarchar(500) NULL,
       FirstColumn nvarchar(500) NULL,
       SecondColumn nvarchar(500) NULL,
       GroupOrder int NULL
)
GO


Sunday, July 24, 2011

JQuery: Write Less, Do More (Part 2)

In our first part we saw some basics of jQuery. In this part we will try to be familiar with some frequently used jQuery event function and also show some example how to talk to server using jQuery, which is also known as core of jQuery.

Wednesday, July 20, 2011

JQuery: Write Less, Do More (Part 1)

JQuery is currently frequently used in web development. Now a day’s it is a basic arsenal for a web developer. Though there are thousands of site and tutorial for learning jQuery I want to write something about jQuery through my own style. In this part we try to be familiar with jQuery and learn the basics of jQuery.
Now what is jQuery? It is a javascript library; usually it reduces the javascript programming. In jQuery which I achieve by writing a line of code if I want to achieve the same thing with javascript I must write more code than jQuery. Hope fully it is easy to learn jQuery and there is huge resource in web. So let’s learn how to start with jQuery.

Thursday, July 14, 2011

Use Regular Expression in SQL Server by using .Net CLR Integration

Regular expression is frequently used in today’s development for various purposes such as validation field, email address validation, set password criteria etc. Dot net supports regular expression also. You can use it in your application easily by referencing the assembly ‘System.Text.RegularExpressions’ . But if the situation occurs when you need to use regular expression in SQLServer then how can you do that? In this article I will show you the way how you can do it.

Monday, May 16, 2011

Write XML Document Programmatically Using C#

In this article simply I will try to explain, how to write an XML document using c#. Extensible Markup Language(XML) was designed to transport and store data, with focus on what data is[1].  I think sometimes programmer needs to write XML document from other source of data. In my article I try to do that as a simple manner.

Wednesday, March 9, 2011

Starting with NHibernet


Reading some useful document finally I can run a one page project using nhibernet. The project is simple as it can only add a record in a database table. But as a beginner with nhibernet I have faced some problem to run the project. In this article I will try to demonstrate the step to work with nhibernet for a beginner. I will show the necessary step to configure the project for working with nhibernet for a begginer.

First step First:  At first I need the Nhibernet. So let’s download it from Download NHibernet. After downloading we will do the following task. 
  1.  Install Nhibernet
  2. Create a simple business object class  
  3. Create a Nhibernet mapping to load and save the business object 
  4.  Configure the Nhibernet
  5. Write a save method to save the data in database
After do the entire step my solution explorer looks like

                                                        Figure: Solution Explorer
Install Nhibernet: Create a folder and name it Nhibernet unzip the downloaded Nhibernet zip file in that nhibernet folder. You will see some folder and file. Add the Nhibernet.dll reference to your project which is in Required_Bins(after unzip Nhibernet this folder will create) folder. That’s all to install Nhibernet.

Create a Simple Business Object Class: Actually in this article we just follow the step to working with Nhibernet. We do not discuss detail about Nhibernet. In this step we will create a simple business object class which is used to save the data in database. In my case I have a table in my test database named ‘t_Department’. So I create a object class for this table. The following figure shows the object explorer of the database.

  

The following figure shows the business object class layout.

Create a NHibernet mapping to load and save the business object: Create a folder 'Mappings' in our NHibernetApp project. Add an xml file and name it 'Department.hbm'. Define Embedded Resource for Build Action for the xml file. Now we add 'nhibernate-mapping.xsd' file in our Department.hbm xml file's Schemas properties so that VS provide us intellisense and validation when we edit xml mapping document. To add the 'nhibernate-mapping.xsd' file follow the following step.
  1. Create a folder name 'SharedLibs' in NHibernetApp project directory using windows explorer.
  2. Copy the 'hibernate-mapping.xsd' file from extracted NHibernet's 'Required_Bins' folder and copy it to 'SharedLibs' folder.
  3. From VS open the  Department.hbm file. Right click and go to properties.
  4. Map the hibernate-mapping.xsd file to Schemas properties.
The following figure shows the Properties window.
Now add the following line in Department.hbm xml file.

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernetApp"   namespace="NHibernetApp.Domian">
  <class name="NHibernetApp.Domian.Department" table="t_Department">

    <id name="OID" column="OID" type="String" unsaved-value="0">
      <generator class="assigned" />
    </id>

    <property name="departmentName" column="department_departmentName" 
              type="String" />
    <property name="facaltyName" column="department_facaltyName" type="String" />
   
  </class>
</hibernate-mapping>

The mapping file looks like the following figure


Look at the class tag's name property. Always use a fully qualified name of the class for name property.

Configure NHibernet: In this step we will see how to configure NHibernet. In my case i use SQL Server 2008. The following step should be followed
  1. Add a xml file to the root of the project (my case it is NHibernetApp).
  2. Named the xml file 'hibernate.cfg.xml'
  3. Set it's 'Copy to Output Directory' to 'Copy always'
  4. Add the following line to the xml file

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.connection_string">
Data Source=REGOR;Database=MVCTest;Uid=sa;Pwd=sa
    </property>
    <property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="dialect">
NHibernate.Dialect.MsSql2008Dialect
    </property>
    <property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
    </property>
    <property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu
    </property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

Please change the connection_string property as your machine. Finally add two more ddl 'NHibernate.ByteCode.LinFu.dll' and 'LinFu.DynamicProxy.dll' in your project references. The ddl's are located in extracted NHibernet folders 'Required_For_LazyLoading\LinFu' folder. That's all, the configuration is complete.


Finally: Finally we will add two more class to save data in database. Just follow the following step
  1. Add a new folder in the project (My case Manager).
  2. Add an interface to the newly added folder (My case DBMgr.cs) .
  3. Add a class file to the added folder (My case RegMgr.cs).
  4. Add the following code to the DBMgr.cs interface

namespace NHibernetApp.Manager
{
    public interface DBMgr
    {
        //IList getDepartments();
        //Department getDepartment(int id);
        void saveDepartment(Department dept);

        //IList getClasses();

    }
} 
Now just implement the DBMgr interface in RegMgr.cs class. The source code of the class would be.

public class RegMgr:DBMgr
{

    Configuration config;
    ISessionFactory factory;

    public RegMgr()
    {
           
       config = new Configuration();
       config.Configure();
       config.AddAssembly(typeof(NHibernetApp.Domian.Department).Assembly);      
       factory = config.BuildSessionFactory();

    }
    
    public void saveDepartment(NHibernetApp.Domian.Department dept)
    {

        ISession session = null;
        ITransaction tx = null;
        try
        {
           session = factory.OpenSession();
           tx = session.BeginTransaction();
                
           if (dept.OID == null)
           {
              dept.OID = "1234";
              session.Save(dept);
           }
           else
           {
              session.Update(dept);
           }
           tx.Commit();
           session.Close();
        }
        catch (Exception ex)
        {
           tx.Rollback();
           session.Close();
               
         }

     }
}

That's all friends. If you want you can download my code from this link. Click Here

Conclusion: I think this article will help the begging for starting with NHibernet first time. I again replay that it is a simple article for begging. If you want to be a specialist on NhHibernet there is no alternative to read books and do more exercise.







Monday, November 1, 2010

Create Radio Button Dynamically like gmail User ID suggestion

Introduction: In my project I face a problem that generate user id dynamically and show it in a radio button list. For example when create a new gmail account user first time supply user id and if the user id is not available the gmail show some user id as suggestion. After some google i found how to generate radio button dynamically but this was not sufficient for me. So I decide to write some thing so that people may get help from my writing.

Procedure: First I create a page that contain
                 1. A text box which is used to supply the user ID.
                 2. A button that is used to check availability.
If the user id is not available then a radio button group with suggested user id will show below the text box. This is the scenario. Let see how can we do that with javascript and asp.Net.

Step1: Add the aspx page that contain the text box and the button. The script of the page is as follows:
 
<%@ Page Title="" Language="C#" MasterPageFile="~/Master Pages/LogedIn.Master" AutoEventWireup="true" CodeBehind="RadioButtonTest.aspx.cs" Inherits="JqueryTest.RadioButtonTest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div>
        User ID:
        <asp:TextBox ID = "txtUserID" runat = "server" />
        <input id="btnCheckID" value="Check availability"  type="button" onclick="usernameChecker();" />
        <span id="spanAvailability"></span>
      
    </div>
    <div id="divRadiolist">
    </div>
   
</asp:Content>

Step2: Now add the necessary javascript code below the button and span. The javascript code is given below:
<script type="text/javascript">
            var usernameCheckerTimer;

            var spanAvailability = document.getElementById("spanAvailability");
            var dvSuggest = document.getElementById("divRadiolist");
            function usernameChecker() {
                var username1 = document.getElementById("ctl00_ContentPlaceHolder1_txtUserID");
                var username = username1.value;
                clearTimeout(usernameCheckerTimer);
              
                    spanAvailability.innerHTML = "<span style='color: #ccc;'>checking...</span>";
                    usernameCheckerTimer = setTimeout("checkUsernameUsage('" + username + "');", 750);
              }

            function checkUsernameUsage(username) {
                // initiate the ajax pagemethod call
                // upon completion, the OnSucceded callback will be executed
                PageMethods.IsUserAvailable(username, OnSucceeded);
            }

            // Callback function invoked on successful completion of the page method.
            function OnSucceeded(result, userContext, methodName) {
                if (methodName == "IsUserAvailable") {

                    if (result == "0") {
                        spanAvailability.innerHTML = "<span style='color: DarkGreen;'>Available</span>";
                        divRadiolist.style.display = "none";
                    }
                    else {
                        spanAvailability.innerHTML = "<span style='color: Red;'>Unavailable</span>";
                        divRadiolist.style.visibility = "visible";
                        /** This code is for show the suggesstion.Added by zafor 2010/10/27  **/
                        var checkAvailable = result.toString().split('|');
                        //Two dimentional array hold suggested user id
                        var arrData = [["0", checkAvailable[0]], ["1", checkAvailable[1]], ["2", checkAvailable[2]], ["3", checkAvailable[3]]];

                        //read div which show available user id
                        var radioDiv = document.getElementById("divRadiolist");
                        var username1 = document.getElementById("ctl00_ContentPlaceHolder1_txtUserID");
                        var username = username1.value;

                        radioDiv.innerHTML = "<p style='color: Red;'>" + username + " is not available but the followings are</p>";
                        //This for loop used to create the radio list
                        for (var i = 0; i < arrData.length; i++) {
                            var createRadioItem = document.createElement("input");
                            createRadioItem.type = "radio";
                            createRadioItem.name = "radioButtonGroup";
                            createRadioItem.id = "radioItem_" + i;

                            createRadioItem.value = arrData[i][1]
                            createRadioItem.setAttribute("onclick", "JavaScript:return getSelectedRadioValue()");

                            var objTextNode = document.createTextNode(" " + arrData[i][1]);

                            var createLabel = document.createElement("label");
                            createLabel.htmlFor = createRadioItem.id;
                            createLabel.appendChild(createRadioItem);
                            createLabel.appendChild(objTextNode);

                            var createBreak = document.createElement("br");

                            radioDiv.appendChild(createLabel);
                            radioDiv.appendChild(createBreak);
                        };

                        /** End the suggestion code  **/
                        divRadiolist.style.display = "block";
                    }
                }
            }
        </script>

  <%-- This javascript function is for select suggesstion. Added by zafor 2010/10/27--%>
  <script type="text/javascript">
          function getSelectedRadioValue() {
                var node = document.getElementsByName('radioButtonGroup');

                for (var i = 0; i < node.length; i++) {
                    if (node[i].checked) {
                        var rad_val = node[i].value;
                    }
                }
                var userID = document.getElementById('ctl00_ContentPlaceHolder1_txtUserID');
                userID.value = rad_val;
            }
 </script>

We use Ajax pageMethods to call the server side method which actually check the user id availability. Since we use master page in that page so add the ScriptManager tag in master page form section and set its EnablePageMethods property true to call the server side method.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods ="true"  > </asp:ScriptManager>

Step3: Now add the following code in code behind page i.e, .cs file.
public static List<string> UserList = new List<string>()
        {
            "shimul","zakir","zafor","sohel","sumon"
        };
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        [System.Web.Services.WebMethod]
        public static string IsUserAvailable(string username)
        {
            string userAvailability = string.Empty;
            bool userExists = false;
           
            string tempOid = string.Empty;

            //Check the username in user list
            foreach (var item in UserList)
            {
                if (item.Equals(username))
                {
                    userExists = true;
                }
            }
            if (!userExists)
                userAvailability += "0";
            else
            {
               
               
                //hold suggested user id
                List<string> LstUserOID = new List<string>();
                System.Random random = new Random();
                while (LstUserOID.Count < 4)
                {
                    tempOid = string.Empty;
                  
                    //create temporary oid
                    tempOid += username + random.Next(0, 100);
                    // test is the id exists in login table

                    if (!UserList.Contains(tempOid))
                    {
                        //if not exists then put it in the list
                        LstUserOID.Add(tempOid);
                    }
                }
                foreach (var item in LstUserOID)
                {
                    userAvailability += item + "|";
                }
            }
            return userAvailability;

        }
In my method i actually use a list that is initialize with some name. I use it so that i test my code as it is working or not. And in IsUserAvailable method i test supplied user id to the list. If the list contains the usert id then it generate some id for suggestion and make string with that id which then send to the javascript function. And finally we show the id in radio button.

Step5: When i run my page I see and supply a user id and check it. I get the following screen shot.




I think that will help you little bit. If any further clarification or any suggestion please write me in a mail.

Shimul Mahmud
azkhairuzzaman@gmail.com

Sunday, October 31, 2010

Pop up a ASP page using javascript and refreash the parent page when close the pop up page

Introduction: In this article I will show how to open a page as pop up using javascript. And when close the pop up page how to refresh the parent page where the pop up page is called. It is simple but  some time it will helpful. Suppose you have a page that contain a grid and a button which pop up a page to add data in the grid. Then you need the mechanism to add data in the grid and refresh the page so that the change reflect the page. Let us see how simple it is.

Step1:  In first step we create a parent page which contains just a button called PoP UP and a text box which show the current time including hour minute and second. The script of the asp page is given below:
<table>
        <tr>
            <td>
                Date:
            </td>
            <td>
                <asp:TextBox ID="txtDate" runat="server" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Button ID="btnPopup" runat="server" Text="PoP UP" OnClick="btnPopup_Click" />
            </td>
        </tr>
    </table>
From this page when we click the PoP UP button a small page will pop up contains some text and a button called OK. After clicking the OK button the pop up page will hide and the parent page will refresh (the date text box show different value).
Step2: For the pop up page I create a asp page named PopupPage. The script of the page given below:
<div>
        <p>
            Hi! How are you.<br />
            This is a pop up page.
        </p>
    </div>
    <table>
        <tr>
            <td>
                <asp:Button ID="btnOk" runat="server" Text="OK" OnClick="btnOk_Click" />
            </td>
        </tr>
    </table>
Step3: Now we write a function to show the pop up page in parent page code behind file i.e, .cs file. The function looks like follows:
void PopUpPage()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script language='JavaScript'>" + "\r\n");
            sb.Append("window.open('PopupPage.aspx', 'CustomPopUp',");
            sb.Append("'width=300,height=300,addressbar=0,menubar=0, resizable=0,");
            sb.Append("status=0,toolbar=0,titlebar=0,location=0,left=250,top=250');");
            sb.Append("</script>\r\n");

            Type t = this.GetType();
            if (!Page.ClientScript.IsClientScriptBlockRegistered(t, "PopupScript"))
            {
                Page.ClientScript.RegisterClientScriptBlock(t, "PopupScript", sb.ToString());
            }
        }
Now call the function from the PoP UP button's click event. It will show the pop up page. When I run my parent page and click the PoP UP button the page looks like the following figure:



Step4: Now the refresh part. In my parent page date show local current time. I want to refresh the page when i click the OK button of pop up page. To do this i add a line in OK buttons click event which close the pop up and refresh the parent page. Just add the following line in OK buttons click event.

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RefreshParent", "<script>opener.location=(window.opener.location.href);window.close();</script>");

After that when i click the OK button the pop up page close and date refresh means the parent page refresh. Which looks like the following figure.

 

Conclusion: This is simple and easy but some time it will be very helpful. If any one will get benefit from it my work will be success. For any query about the article please send me a mail.

Shimul Mahmud
azkhairuzzaman@gmail.com




Tuesday, October 19, 2010

Store Image and Video in Database using ASP.Net and C#

Introduction:
It is a common case to store image and video in database. But store image/video in database takes huge amount of space. So after some time in Google I learn a technique to store image/video in database easily. In my case I store only the name of the image/video in a varchar field in database and the actual file uploaded in the server. Let see the simple but very useful technique to store image/video.
Step1: First we create a simple ASP.Net project named StoreImage. An asp page and a folder to load the image/video. The solution explorer looks like

Step2: In aspx page I use only a file up loader control of asp and a two button one for upload and another for save. The aspx page code as follows,

<form id="uploadForm" runat="server">

<table>

<tr>

<td>

Uploaded Image:

td>

<td>

<asp:Image ID="imageFile" runat="server" />

td>

tr>

<tr>

<td>

<asp:FileUpload ID="fileUploadImage" runat="server" />

td>

<td>

<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click"/>

td>

tr>

<tr>

<td colspan="2">

<asp:Label ID="lblError" runat="server" ForeColor="Red">asp:Label>

td>

tr>

<tr>

<td colspan="2">

<asp:Button ID="btnSave" runat="server" Text="Save Image"

onclick="btnSave_Click" />

td>

tr>

table>

form>



Step3: In the code behind use the following code to upload the image in server’s particular folder in our case the folder is ‘Uploaded Image’

protected void btnUpload_Click(object sender, EventArgs e)

{

if (fileUploadImage.PostedFile != null && fileUploadImage.PostedFile.ContentLength > 0)

{

//Get the file extension and check if it is jpg,png or wmv.

fileExtension = Path.GetExtension(fileUploadImage.PostedFile.FileName);

//If file type jpg/png/wmv then enter the block

if (fileExtension.ToLower().Equals(".jpg") || fileExtension.ToLower().Equals(".png") || fileExtension.ToLower().Equals(".wmv"))

{

//get file size

fileSize = fileUploadImage.PostedFile.ContentLength;

//if file size more than 4MB then show error message

if (fileSize / 1024 > 4096)

{

lblError.Text = "File size can not be more than 4MB";

return;

}

else

{

//get the uploaded file name

fileName = Path.GetFileName(fileUploadImage.PostedFile.FileName);

//save the file in location of server

fileUploadImage.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("~/Uploaded Image/" + Path.GetFileName(fileUploadImage.PostedFile.FileName)));

//get the server URI

ServerUri = System.Configuration.ConfigurationManager.AppSettings["ServerUrl"].ToString();

//Create the image URI

imageUri = ServerUri + "/Uploaded Image/" + fileName;

//Show the uploaded iamge in imagefile

imageFile.ImageUrl = ServerUri + "/Uploaded Image/" + fileName;

}

}

else

{

lblError.Text = "Unsupported file format. Please select jpg, pig or wmv file";

return;

}

}

else

{

lblError.Text = "No file selected";

return;

}

}

We assume that we just upload jpg png or wmv file.

To get the server URL we add an extra line in web.config file. The line is

<appSettings>

<add key ="ServerUrl" value="http://localhost:4122" />

appSettings>

For your case it may be different. After show the location of file and click the Upload button my page looks like


Step4: Now we want to save the image name in database. To do so first we read the file name from server then we save it to database. Suppose our database hold a table named image which has two field OID and ImageName. So to save it in database we need the following code in the Save button’s event handler.

bool SaveImage()

{

bool result = false ;

if (imageUri != null)

{

string[] imageName = imageUri.Split('/');

//check the file extension if the extension jpg/png then content type IMG

if (imageName[imageName.Length - 1].Contains("jpg") || imageName[imageName.Length - 1].Contains("png"))

{

SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

string query = "";

query += " insert into t_ image (OID, ImageName) ";

query += " values (@OID, @ ImageName) ";

try

{

SqlCommand command = new SqlCommand();

command.Connection = conn;

command.CommandType = System.Data.CommandType.Text;

command.CommandText = query;

command.Parameters.AddWithValue("OID", "1");

command.Parameters.AddWithValue("ImageName ", imageName[imageName.Length - 1]);

conn.Open();

if (command.ExecuteNonQuery() == 1)

{

result = true;

}

}

catch (Exception ex)

{

result = false;

}

finally

{

conn.Close();

conn.Dispose();

}

}

}

return result;

}


protected void btnSave_Click(object sender, EventArgs e)

{

if (SaveImage())

{

lblError.Text = "Image Save Successfully";

}

}

Here imageUri is a static global field which hold the image url when upload the image to the server.

Hope it will help you little bit. Thank you very much. For any query please don’t be hesitate to write me.

Shimul Mahmud

azkhairuzzaman@gmail.com