1
Answer

How to send image via webservices with other information.

haneef shaik

haneef shaik

15y
2.2k
1
Hi to all,

I want to send image through other details.

For Example My xml is like this and I want to send like as string (Return type as string).

<xml>
<uid>xxxxx </uid>
<logoimg>Here My Byte code<logoimg>
......
......
<xml>

How can i do it, user after getting the xml how he can save it as image again..

Please give me all details..
Answers (1)
0
Jignesh Trivedi

Jignesh Trivedi

NA 66.4k 14.2m 12y
hi,

datareader.Dispose() method ensures all resources associated with the current DataReader object instance are released.

hopet thsi help.
0
Glen Robson

Glen Robson

NA 46 22k 12y
Thanks Jignesh what would reader2.Dispose(); do?
0
Jignesh Trivedi

Jignesh Trivedi

NA 66.4k 14.2m 12y
hi,

Back to your original code.

try..

reader2.Dispose(); after closing datareader.

hope this help.
0
Narayan

Narayan

NA 724 36.3k 12y
Hi

A clean way of doing this just create a class having three properties

public class MyQty
{
        public string
LQty{get;set;}
       
public string MQty{get;set;}
        public string SQty{get;set;}
}

In your admin.cs where you are connecting to database, try return the object of MyQty class and you are ready to use it any where.

Admin.cs

private MyQty LoadQuantity(int ProdID)
{
        MyQty obj=null;
        using(SqlConnection con2=new
SqlConnection(WebConfigurationManager.ConnectionStrings["Geordie_Jeans"].ConnectionString))
        {
                using(
SqlCommand cmd2 = new SqlCommand("PR_GET_QUANTITY", con2){
       cmd2.Parameters.Add("@ID", SqlDbType.Int).Value = prodID;
       con2.open();
        using(SqlDataReadear= cmd2.ExecuteReader())
        {
                obj=new MyQty();
                // Here set the property of the object
        }
                }
        }

return obj;
}

Thanks,
narayan
0
Glen Robson

Glen Robson

NA 46 22k 12y
Thanks for the reply. However i think this sounds a little overkill just to close the connection. There must be another way to close it?

This is not the only place that i am having this problem. I have over 70 other situations like this so to go through and change all of them would take a very long time.

Boldonglen
0
Jignesh Trivedi

Jignesh Trivedi

NA 66.4k 14.2m 12y

Hi,
OK, I forgot that this code is in aspx.cs file
Can we move your code in admin.cs?
Create One class like in admin.cs


public class QuantData
{
    public string LQty { get; set; }
    public string MQty { get; set; }
    public string SQty { get; set; }
}


update.aspx.cs

private void LoadQuantity(int ProdID)
{
    Admin admin = new Admin();
    QuantData q = new QuantData();
    q = admin.GetQuantData(ProdID);
    if (q != null)
    {
        txtLQty.Text = q.LQty;
        txtMQty.Text = q.MQty;
        txtSQty.Text = q.SQty;
    }
}

Admin.cs

SqlConnection con2;
static string connectionString = WebConfigurationManager.ConnectionStrings["Geordie_Jeans"].ConnectionString;
public SqlDataReader GetQuant(int prodID)
{
    SqlCommand cmd2 = new SqlCommand("PR_GET_QUANTITY", con2);
    cmd2.CommandType = CommandType.StoredProcedure;

    cmd2.Parameters.Add("@ID", SqlDbType.Int).Value = prodID;
    SqlDataReader reader2 = null;
    try
    {
        reader2 = cmd2.ExecuteReader();
        return reader2;
    }
    catch (Exception err)
    {
        throw err;
    }
}
public void OpenConnection()
{
    if (con2 == null)
    {
        con2 = new SqlConnection(connectionString);
    }
    if (con2.State == ConnectionState.Closed)
    {
        con2.Open();
    }
}
public void CloseConnection()
{
    if (con2 != null && con2.State == ConnectionState.Open)
    {
        con2.Close();
    }
}
public QuantData GetQuantData(int ProdID)
{
    OpenConnection();
    SqlDataReader reader2 = GetQuant(ProdID);
    QuantData q = new QuantData();
    int count = reader2.FieldCount;
    while (reader2.Read())
    {
        for (int i = 0; i < count; i++)
        {
            if (reader2["PROD_SIZE"].ToString() == "L")
            {
                q.LQty = reader2["PROD_QUANT"].ToString();
            }
            if (reader2["PROD_SIZE"].ToString() == "M")
            {
                q.MQty = reader2["PROD_QUANT"].ToString();
            }
            if (reader2["PROD_SIZE"].ToString() == "S")
            {
                q.SQty = reader2["PROD_QUANT"].ToString();
            }
        }
    }
    reader2.Close();
    CloseConnection();
    return q;
}

0
Glen Robson

Glen Robson

NA 46 22k 12y
Ok i think i know what you mean. So you think i should close the reader in the .aspx.cs file and not in my class file (.cs)?

Look something like this:

private void LoadQuantity(int ProdID)
        {
            SqlDataReader reader2 = Geordie_Jeans.Classes.AdminControl.GetQuant(ProdID);

            int count = reader2.FieldCount;
            while (reader2.Read())
            {
                for (int i = 0; i < count; i++)
                {
                    if (reader2["PROD_SIZE"].ToString() == "L")
                    {
                        txtLQty.Text = reader2["PROD_QUANT"].ToString();
                    }
                    if (reader2["PROD_SIZE"].ToString() == "M")
                    {
                        txtMQty.Text = reader2["PROD_QUANT"].ToString();
                    }
                    if (reader2["PROD_SIZE"].ToString() == "S")
                    {
                        txtSQty.Text = reader2["PROD_QUANT"].ToString();
                    }
                }
            }

        reader2.Close();
            
        }


This seems to work, however i cannot access the connection (con) to close it within this block of code above. It seems the only way i will be able to close my connection is in the class file under my GetQuant() method? I can see that you have asked me to use a global vairable for the connection. However i dont feel that this is very secure. Is there any other way that i could close the connection?


Thanks Boldonglen

0
Jignesh Trivedi

Jignesh Trivedi

NA 66.4k 14.2m 12y
hi,

Do not close reader and connection in finally block of GetQuant method.
Intead of

close reader and connection after datareader.read() method.

for same make connection as a globle variable.

Let me know if you not solved ur problem.

hope this help.