你能帮帮我吗?我没有得到任何错误bt所需的o / p没有得到显示 [英] Can u pls help me? i m not getting any error bt the required o/p doesnt get dispalyed

查看:122
本文介绍了你能帮帮我吗?我没有得到任何错误bt所需的o / p没有得到显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要显示网格视图,这里插入的值不会插入SQL中



.cs页面



i m suppose to get the grid view displayed bt here the inserted value doen''t get inserted in SQL

.cs page

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页面:





aspx page:

<%@ 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]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

it will be like below



it will be like below

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







as you are using parameterized query.



谢谢




as you are using parameterized query.

Thanks


这篇关于你能帮帮我吗?我没有得到任何错误bt所需的o / p没有得到显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆