Click here to Skip to main content
15,867,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m suppose to get the grid view displayed bt here the inserted value doen't get inserted in SQL

.cs page

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using System.Configuration;

public partial class candidate_details_no_BL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CandidateDetails();
        }
    }
    protected void CandidateDetails()
    {   try
        {   SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=FirmusTraining; Integrated Security = True;");
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * from candidate_details", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);// bridge between db and ds
            DataSet ds = new DataSet();
            da.Fill(ds);// filling values of da in ds
            if (ds.Tables[0].Rows.Count > 0)
            {
                gvD.DataSource = ds;
                gvD.DataBind();
            }
            else
            {
                ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());//new row cr(auto generate) adding it in ds tables
                gvD.DataSource = ds;//assign columns// ds putting in gridview
                gvD.DataBind();// values bind
                int columncount = gvD.Rows[0].Cells.Count;//intitialzing and declaring column1
                gvD.Rows[0].Cells.Clear();//clearing the junk values2
                gvD.Rows[0].Cells.Add(new TableCell());//now add the table in gv3
                gvD.Rows[0].Cells[0].ColumnSpan = columncount;// gv's column, columnspan is columncount 4
                gvD.Rows[0].Cells[0].Text = "No Records Found";// no details found when no records entered5
            }
        }
        catch (Exception exp)
        {
        }
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string filepath = gvD.DataKeys[gvrow.RowIndex].Value.ToString();//6
        Response.ContentType = "resume/text";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filepath + "\"");//7
        //Response.TransmitFile(Server.MapPath(filepath));
        Response.TransmitFile(Server.MapPath("resume/" + filepath));//8
        Response.End();
    }
    protected void SaveCandidateDetails(object sender, EventArgs e)// fileupload
    {   try
        {   string filepath = Path.GetFileName(fleUploadResume.PostedFile.FileName);//9
            string name = txtCandidateName.Text;
            string Qualification = txtQualification.Text;
            string SkillSet = txtSkill.Text;
            fleUploadResume.SaveAs(Server.MapPath("resume/" + filepath));
            SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());//10
            con1.Open();
            SqlCommand cmd = new SqlCommand("insert into candidate_details(Name,Qualification,Skillset,filepath) values('" + txtCandidateName.Text + "','" + txtQualification.Text + "','" + txtSkill.Text + "','" + filepath + "')", con1);
            cmd.Parameters.AddWithValue("@Name", name);
            cmd.Parameters.AddWithValue("@Qualification", Qualification);
            cmd.Parameters.AddWithValue("@Skillset", SkillSet);
            cmd.Parameters.AddWithValue("@fleUploadResume", filepath);
            cmd.ExecuteNonQuery();
            con1.Close();
        }
        catch (Exception ex)
        {
        }

    }
}


aspx page:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="candidate_details_no_BL.aspx.cs" Inherits="candidate_details_no_BL" %>

<!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 id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Candidate Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtCandidateName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="Candidate Qualification"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtQualification" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="Candidate Skillset"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtSkill" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="Resume"></asp:Label>
                </td>
                <td>
                    <asp:FileUpload ID="fleUploadResume" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <asp:Button ID="Submit" runat="server" Text=" Submit " OnClick="SaveCandidateDetails" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <asp:Label ID="Label5" runat="server" Style="text-align: center" Text="Candidate Details"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div>
                        <asp:GridView runat="server" ID="gvD" AutoGenerateColumns="False" CssClass="gvD"
                            HeaderStyle-BackColor="#61A6F8" Width="226px" CellPadding="4" ForeColor="#333333"
                            GridLines="None" DataKeyNames="Filepath">
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:BoundField DataField="Name" HeaderText="Candidate Name" />
                                <asp:BoundField DataField="Qualification" HeaderText="Qualification" />
                                <asp:BoundField DataField="skillset" HeaderText="SkillSet" />
                <asp:TemplateField HeaderText="FilePath">
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"></HeaderStyle>
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EFF3FB" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 28-Feb-13 21:19pm
v2
Comments
OriginalGriff 1-Mar-13 3:19am    
How the heck do you expect us to answer that?
We have no idea what your "expected o/p" is supposed to be, and also no idea what you do get.
So tell us these things! And stop posting your entire program - give us the necessary fragments so we don't have to wade through to try and find the bits we need to look at!
Help us, to help you!
Use the "Improve question" widget to edit your question and provide better information.
Jibesh 1-Mar-13 3:20am    
this is reposted question. http://www.codeproject.com/Questions/554908/canplusuplusplsplushelpplusmeplusNOpluswithplusthi

OP created some more and I delete others. hope I can delete this one too.
vidya.s.no1 1-Mar-13 3:31am    
when there is no error what do u expect me to post.

here i m inserting values which has to gt stored in db then displayed in the same page in gridview.

sorry if i have posted the whole site didnt know what to post
OriginalGriff 1-Mar-13 3:53am    
Sit back for a moment, and take a deep breath.

OK, lets start again.
Imagine you are here to help, and you open this question. Remember, you can't see the original posters screen, homework instructions, or access his HDD or read his mind. All you have to work from is the text in the question.

So lets look at it: " i m not getting any error bt the required o/p doesnt get dispalyed"
That doesn't tell you anything. It says: "This compiles." "This doesn't work"
It doesn't tell you what it should do if it does work. It doesn't tell you what it does at the moment. You can't run it, because it needs database information you don't have. So what answer can you give?

You can't. You need information that just hasn't been given. It's like your car broke down in the middle of nowhere and you rang the garage. You told them "my car broke" and put the phone down. How long do you think you are going to have to wait before they arrive to fix it?

So don't get snotty and frustrated when you don't get an answer - we can't help you if you don't tell us what we need to know.


BTW: Stop using txtspeak - it annoys people who know you have a keyboard. Stop posting repeat questions. We can read and remember and if you come over as an impatient little child, you will be treated as such. And use proper capitalization - all lower case is seen as childish on a professional site.
Nelek 1-Mar-13 10:37am    
If comments could be voted... that would be a big 5

1 solution

it will be like below

C#
SqlCommand cmd = new SqlCommand("insert into candidate_details(Name,Qualification,Skillset,filepath) values(@Name,@Qualification,@Skillset,@filepath)", con1);



as you are using parameterized query.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900