Divin Mfwamba

Divin Mfwamba

  • NA
  • 22
  • 10.7k

Not saving in my database

Aug 16 2013 4:23 AM
Hi!

I can't save on my database a picture. I receive this message when try ro run my webpage:
No overload for method 'execution' takes '7' arguments


Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
    public string GetConnectionString()
    {       
        return System.Configuration.ConfigurationManager.ConnectionStrings
            ["divin"].ConnectionString;       
    }
    private void execution(string fname, string lname, string dob, string gender, string fathername, string contact, string address, Image photo)
    {       
       
        SqlConnection conn = new SqlConnection(GetConnectionString());
       
        string sql = "INSERT INTO onlineapplication (fname, lname, dob, gender, fathername, contact, address,photo) VALUES "
        + " (@fname, @lname, @dob, @gender, @fathername, @contact, @address, @photo)";
       
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);        
            SqlParameter[] pram = new SqlParameter[8];        
            pram[0] = new SqlParameter("@fname", SqlDbType.VarChar, 50);
            pram[1] = new SqlParameter("@lname", SqlDbType.VarChar, 50);
            pram[2] = new SqlParameter("@dob", SqlDbType.VarChar, 50);
            pram[3] = new SqlParameter("@gender", SqlDbType.Char, 10);
            pram[4] = new SqlParameter("@fathername", SqlDbType.VarChar, 50);
            pram[5] = new SqlParameter("@contact", SqlDbType.Int, 20);
            pram[6] = new SqlParameter("@address", SqlDbType.VarChar, 100);
            pram[7] = new SqlParameter("@photo", SqlDbType.Image);
           
            pram[0].Value = fname;
            pram[1].Value = lname;
            pram[2].Value = dob;
            pram[3].Value = gender;
            pram[4].Value = fathername;
            pram[5].Value = contact;
            pram[6].Value = address;
            pram[7].Value = photo;

            for (int i = 0; i < pram.Length; i++)
            {
                cmd.Parameters.Add(pram[i]);
            }
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch(System.Data.SqlClient.SqlException ex_msg)
        {
            string msg = "Error occured while inserting";
            msg += ex_msg.Message;
            throw new Exception(msg);
        }
        finally
        {        
            conn.Close();
        }
   
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void submit_Click(object sender, EventArgs e)
    {       
        if(fname.Text=="")
        {
            Response.Write("Please complete the form.");
        }
        else
        {
            //bug on this line.
            execution(fname.Text,lname.Text,dob.Text,gender.Text,fathername.Text,contact.Text,address.Text);
            conform.Visible = true;
            fname.Text="";
            lname.Text="";
            dob.Text="";
            gender.Text="";
            gender.Text="";
            fathername.Text="";
            contact.Text="";
            address.Text="";        
           
           
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////
default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Simple Application Form in ASP.Net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <strong><span style="font-size: 14pt; color: #0000ff">Simple Application Form In ASP.Net</span></strong><br />
            <br />
            <br />
            <br />
            <table>
                <tr>
                    <td style="width: 123px">
                        First Name</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="fname" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Last Name</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="lname" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Date of Birth</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="dob" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Gender</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="gender" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Father's Name</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="fathername" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Contact Number</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="contact" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Address</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:TextBox ID="address" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                        Select Photo</td>
                    <td style="width: 63px">
                        :</td>
                    <td style="width: 193px">
                        <asp:FileUpload ID="FileUpload1" runat="server"/></td>
                </tr>
                <tr>
                    <td style="width: 123px; height: 21px">
                    </td>
                    <td style="width: 63px; height: 21px">
                    </td>
                    <td style="width: 193px; height: 21px">
                        <asp:Label ID="conform" runat="server" Text="Submitted, thank you !" Visible="False"
                            Width="152px"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 123px">
                    </td>
                    <td style="width: 63px; text-align: center">
                    </td>

                    <td style="width: 193px">
                        <asp:Button ID="submit" runat="server" Text="Submit" OnClick="submit_Click" /></td>
                </tr>
               
            </table>
        </div>
        <br />
        <br />
        <strong><span style="text-decoration: underline">Database Details</span></strong><br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
            EmptyDataText="There are no data records to display.">
            <Columns>
                <asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
                <asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
                <asp:BoundField DataField="lname" HeaderText="lname" SortExpression="lname" />
                <asp:BoundField DataField="dob" HeaderText="dob" SortExpression="dob" />
                <asp:BoundField DataField="gender" HeaderText="gender" SortExpression="gender" />
                <asp:BoundField DataField="fathername" HeaderText="fathername" SortExpression="fathername" />
                <asp:BoundField DataField="contact" HeaderText="contact" SortExpression="contact" />
                <asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
                <asp:BoundField DataField="photo" HeaderText="photo" SortExpression="photo" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:divin %>"
            ProviderName="<%$ ConnectionStrings:divin.ProviderName %>"
            SelectCommand="SELECT [id], [fname], [lname], [dob], [gender], [fathername], [contact], [address], [photo] FROM [onlineapplication]">
        </asp:SqlDataSource>
   
    </div>
    </form>
</body>
</html>

Answers (7)