Posts Tagged ‘parameters’

Asp.Net MVC Post Controller Not being hit

Monday, August 23rd, 2010

I’ve got an Asp.Net mvc web app that has a controller action to handle a post with an int as a parameter. I’ve set a breakpoint in the action and it is never getting hit. Here is the controller action setup:

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult AddTestNumber(int number)
    {

And here is the jquery that calls the action:

$.post("/testController/AddTestNumber/852852");

I’ve tested it with no parameters and it hit the breakpoint. I havent changed any routing, so thats set to default.

This seems like it should be very simple fix that I’m overlooking

Android AdWhirl & Adsense 3.1

Monday, August 23rd, 2010

Hi,
Adsense (Google Adsense Sdk 3.1) alone works fine in my app.

When I use AdWhirl I see in my Log always:

:WARN/AdWhirl SDK(562): AdSense company name and app name are required parameters

How do I send this params right so also AdWhirl transfer it to
Adsense?? (i did not deleted the params i used for ONLY ADSENSE.. so they are still there??)

Thx
chris

display jquery returned data correctly

Monday, August 23rd, 2010

hi…i’ve been a prototype user for a few years, and now for several reasons, i’m moving to jquery.. but still have yet familiarize myself with jquery’s syntax.. my question is

how do I convert this prototype code to jquery correctly?

new Ajax.Updater('displayArea', 'shoutbox.php', { method:'post',
    parameters: {action: 'display', some_data: some_data}
});

and here’s what i did:

$.post("shoutbox.php", {action: "display", some_data: some_data}, function(data){$("#displayArea").text(data);},"html");

i got the exact return result from jquery and prototype, but the problem is, when jquery updates the “displayArea”, it’s not quite what I expected. the returned data has some html codes in it, and instead of displaying a new line for the html tag ‘br’, jquery just display the ‘br’ in plain text. what i means is it’s displaying html codes, and that’s not what I want. hope you all get what i meant….

thanks

Inserting NULL when no file is provided in upload control?

Sunday, August 22nd, 2010

I had web form in which user can upload image and I had two file upload first for product image and the second for logo image.

In the file upload for logo image user can upload also he can not upload any image. I tried to insert NULL data when the user doesn’t upload an image in logo file upload.

And I had Data list which I display the images. I created a GenericHandler to display image, but when the DataList loads with images this error appears:

Specified argument was out of the range of valid values
Parameter name: offset

I know the error occurs because I inserted a NULL image, but I couldn’t solve this error.

Note: when I saw the data in SQL, I found the NULL image was inserted with data type “Binary data”…

My C# code:

protected void BtnSubmit_Click(object sender, EventArgs e)
{
    int RowAffected = 0;

        byte[] imageSize = new byte
                      [FileUpload1.PostedFile.ContentLength];
        HttpPostedFile uploadedImage = FileUpload1.PostedFile;
        uploadedImage.InputStream.Read
           (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

            using (SqlConnection con = Connection.GetConnection())
            {
                SqlCommand Com = new SqlCommand("Insert_IntoModel", con);
                Com.CommandType = CommandType.StoredProcedure;

                    SqlParameter UploadedImage = new SqlParameter
                              ("@Image", SqlDbType.VarBinary, imageSize.Length);
                    UploadedImage.Value = imageSize;
                    Com.Parameters.Add(UploadedImage);
                    if (FU2.PostedFile == null && FU2.PostedFile.FileName == "")
                    {

                        Com.Parameters.Add("@Logo", SqlDbType.VarBinary).Value = DBNull.Value;
                    }
                    else
                    {
                        byte[] imageSize2 = new byte
                         [FU2.PostedFile.ContentLength];
                        HttpPostedFile uploadedImage2 = FU2.PostedFile;
                        uploadedImage2.InputStream.Read
                           (imageSize2, 0, (int)FU2.PostedFile.ContentLength);

                        SqlParameter UploadedImage2 = new SqlParameter
                                 ("@Logo", SqlDbType.VarBinary, imageSize2.Length);
                        UploadedImage2.Value = imageSize2;
                        Com.Parameters.Add(UploadedImage2);
                    }
                    RowAffected = Com.ExecuteNonQuery();
                    if (RowAffected > 0)
                    {
                        LblResult.Visible = true;
                        LblResult.Text = "Successfully Proccess";
                        Tbl.Visible = false;
                    }
                }

             }
        }

Generic Handler:

public class ModelLogo : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
    using (System.Data.SqlClient.SqlConnection con = Connection.GetConnection())
    {
        string Sql = "Select Logo From Model Where Id=@Id";
        System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(Sql, con);
        com.CommandType = System.Data.CommandType.Text;
        com.Parameters.Add(Parameter.NewInt("@Id", context.Request.QueryString["Id"].ToString()));
        System.Data.SqlClient.SqlDataReader dr = com.ExecuteReader();
        if (dr.Read() && dr != null)
        {

            Byte[] bytes = (Byte[])dr["Logo"];
            context.Response.BinaryWrite(bytes);
            dr.Close();
        }
    }
}

insert null data when I donot use file upload

Sunday, August 22nd, 2010

I had web form wich user can upload image and I had two file upload first for product image and the second for logo image .in file upload for logo image user can upload also he can donot upload image i tried to insert null data when user donot upload image in logo file upload but I couldnot .

protected void BtnSubmit_Click(object sender, EventArgs e)
{
int RowAffected = 0;

        byte[] imageSize = new byte
                      [FileUpload1.PostedFile.ContentLength];
        HttpPostedFile uploadedImage = FileUpload1.PostedFile;
        uploadedImage.InputStream.Read
           (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);

            using (SqlConnection con = Connection.GetConnection())
            {
                SqlCommand Com = new SqlCommand("Insert_IntoModel", con);
                Com.CommandType = CommandType.StoredProcedure;

                    SqlParameter UploadedImage = new SqlParameter
                              ("@Image", SqlDbType.VarBinary, imageSize.Length);
                    UploadedImage.Value = imageSize;
                    Com.Parameters.Add(UploadedImage);
                    if (FU2.PostedFile == null && FU2.PostedFile.FileName == "")
                    {

                        Com.Parameters.Add("@Logo", SqlDbType.VarBinary).Value = DBNull.Value;
                    }
                    else
                    {
                        byte[] imageSize2 = new byte
                         [FU2.PostedFile.ContentLength];
                        HttpPostedFile uploadedImage2 = FU2.PostedFile;
                        uploadedImage2.InputStream.Read
                           (imageSize2, 0, (int)FU2.PostedFile.ContentLength);

                        SqlParameter UploadedImage2 = new SqlParameter
                                 ("@Logo", SqlDbType.VarBinary, imageSize2.Length);
                        UploadedImage2.Value = imageSize2;
                        Com.Parameters.Add(UploadedImage2);
                    }
                    RowAffected = Com.ExecuteNonQuery();
                    if (RowAffected > 0)
                    {
                        LblResult.Visible = true;
                        LblResult.Text = "Successfully Proccess";
                        Tbl.Visible = false;
                    }
                }

             }
        }

Problem passing parameters with javascript eval function… What am i doing wrong?

Sunday, August 22nd, 2010

Hi everybody,
as usual i come here after testing around for hours and not having any clue what i am doing wrong ;-) I am not an javascript expert so i suppose this will cause some rolling eyes ;-) Sorry about that. I am now at a point where i tried to code somehting in a more readable way. Seperating functions in classes etc… What i want to achieve is something like this:


modules.create(‘streamModule’,'leftColumn’)
which will call
streamModule.create()


NOW THE THING I DONT GET TO WORK:
Calling modules.create(‘streamModule’,'leftColumn’) always results in
Reference Error: leftColumn is not defined???
The id in the call: eval(type +”.create(“+id+”,”+target”)”); is always passed correctly but the target parameter is not??? What am i doing wrong?

Any help would be very very appreciated!!!!! Thank you!

var modules = {
    _map    : [],

    create: function(type,target) {

    if(type == undefined) return false;
    if(target == undefined) return false;

    //Store id in map
    this._map.push(id = createID());

    //Call create function of module
    eval(type +".create("+id+","+target")");
    }
}

[...]

var streamModule = {

create: function() {
    $.log(target)
   }
}

[...]

modules.create('streamModule','leftColumn')

C++ prototype parameter names

Sunday, August 22nd, 2010

In my header, I have a prototype declaration like this:

void move(int, int);

I can omit the parameter names, that’s how I’m used to it from C. I do that so that I don’t have to keep the parameter names in sync – it’s extremely confusing if they differ between prototype and implementation.

Right now, I’m documenting all of my code with Doxygen, and I decided to put all comments into the header. Now I have to refer to parameter names that are defined in the implementation but not in the header: I find that confusing.

/**
 * Moves the entity to the specified point.
 * @param x The x coordinate of the new position.
 * @param y The y coordinate of the new position.
 */
void move(int, int);

In the generated Doxygen HTML, it is not easy to figure out which parameter is which. Of course, one could follow the same order here, but if one has many parameters, it is still confusing.

The alternative would be to duplicate parameter names and try to keep them in sync. However, some people don’t encourage this approach, saying that header parameters should start with a double underscore so that the user of a method can not possibly use the same name (names starting with __ are disallowed in C++).

How do you do it?

TableModelListener and multiple column validation

Sunday, August 22nd, 2010

Hello:

This is the first time for me to post here, so sorry if I made some mistake.

I am working on a JTable which column data have to verify some parameters, for example:

Column 3 values > 30
Column 4 values > 10
Column 5 values > 4

Also the first 2 columns are filled “automatically”, putting 0s in the rest of the columns.

If that data is correct, in the Column 5 I would show an image of a tick, otherwise, I would show an image of a warning.

For verifying this I use the following code

    ImageIcon accept = new javax.swing.ImageIcon(getClass().getResource("/resources/accept.png"));
    ImageIcon deny = new javax.swing.ImageIcon(getClass().getResource("/resources/exclamation.png"));

    public void tableChanged(TableModelEvent e) {
        int row = e.getFirstRow();
        double d1 = Double.valueOf(jTable.getValueAt(row, 2).toString());
        double d2 = Double.valueOf(jT.getValueAt(row, 3).toString());
        double d3 = Double.valueOf(jT.getValueAt(row, 4).toString());

        if(d1>MAX_A||d2>MAX_B||d3>MAX_C){
            jTable.setValueAt(deny, row, 5);
        }
        else{
            jTable.setValueAt(accept, row, 5);
        }
    }

The problem of this code is that returns a Stack Overflow, and I don’t know how to handle this.

Is there any other way to implement some verifier on a table that implies multiple cells?

Thanks in advance.

Store multiple images in SQL database

Sunday, August 22nd, 2010

I’m trying to store the images from three picturebox’s I have on a form in a SQL table.
I was trying to loop through the three picturebox controls on the form and add them via:

Dim DBConnection As New SqlConnection("CONNECTIONSTRING")
    Dim strSQL As String = "INSERT INTO Knowledge_Base (ID_Number, Image1, Image2, Image3) VALUES (@ID_Number, @PictureEdit1, @PictureEdit2, @PictureEdit3)"
    Dim ms As New MemoryStream
    Dim pictureArray As New ArrayList
    Dim cmd As New SqlCommand(strSQL, DBConnection)

    Dim counter As Integer = 0

   For Each ctrl As Control In Me.Controls
        If TypeOf ctrl Is PictureBox Then
            CType(ctrl, PictureBox).Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            pictureArray.Add(ms.GetBuffer)
            ms.Flush()
            cmd.Parameters.Add(New SqlParameter("@" & ctrl.Name, SqlDbType.Image)).Value = pictureArray(counter)
            counter = counter + 1
        End If
    Next

   cmd.Parameters.Add(New SqlParameter("@ID_Number", SqlDbType.NVarChar, 50)).Value = TxtBID_Number.Text

  DBConnection.Open()
    cmd.ExecuteNonQuery()
    DBConnection.Close()

But it always seems to store the last image in all three colums?

Execute SQLite Inserts in several foreach loops in C# ?

Saturday, August 21st, 2010

Hello everybody,

this is my code I have:

I have read that setting up the CommandText should happen only once and not in a loop… but how do I then get the individually item data from the foreach?

Someone smart enough to refactor that code, that would be nice :)

using (SQLiteTransaction trans = DataAccess.ConnectionManager.BeginTransaction())
            {
                using (SQLiteCommand com = new SQLiteCommand(DataAccess.ConnectionManager))
                {   // How can I Add the parameters here If they are only known in the foreach loop ???
                    com.Parameters.Add(new SQLiteParameter("@date", day.SchooldayDate));
                    com.Parameters.Add(new SQLiteParameter("@periodnumber", period.PeriodNumber));
                    com.Parameters.Add(new SQLiteParameter("@schoolclasscode", period.SchoolclassCode));

                    foreach (var week in weekList)
                    {
                        foreach (var day in week.Days)
                        {
                            foreach (var period in day.Periods)
                            {
                                com.CommandText = "Insert into tablename (date,periodnumber,schoolclasscode) Values (@date,@periodnumber,@schoolclasscode)";

                            }
                        }
                    }

                    com.ExecuteNonQuery();
                }
                trans.Commit();
            }