本文介绍了数据和图像填充在两行。我想将它们绑定在一个单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要问这是第二次。我要弄清楚使你能帮助我:)好了,让我们开始。

我有一个注册过程。我分裂过程分成两个页面。第一页是仅用于个人信息。然后当我点击下一步按钮就会出现下一个页面(一项PostBackUrl)这页是上传照片的页面。它们工作得很好!数据和图像显示在我的gridview的控制。但我的问题是在这里:正如你可以在下面的图中看到。数据被填充在两行!我希望他们能够出现在只有单排!我认为这个问题是从第1页数据库不继续进行。这就是为什么当我上传图片页面2上的数据库将创造另一个记录。嗯...有什么问题:)我不知道该怎么做。请帮助!

示于下表中的数据仅DUMMY。请不要认真对待它。

这里的code为INSERT / UPDATE为PersonalINFO.aspx页:

 < ASP:的AccessDataSource =服务器ID =AccessDataSource1的DeleteCommand =删除[PendingRecords] WHERE [ID] =?将InsertCommand =INSERT INTO [PendingRecords]([用户名],[密码],[名字],[姓氏],[中间名],[地址],[两性],[ContactNumber],[PlateNumber],[颜色],[品牌],[LiscensedNumber])VALUES(?,?,?,?,?,?,?,?,?,?,?,?)的UpdateCommand =UPDATE [PendingRecords] SET [用户名] = [密码] =?,[名字] = [姓氏] = [中间名] = [地址] = [两性] =?[ContactNumber] =?[PlateNumber] =?[颜色] = ?[品牌] =?[LiscensedNumber] =?WHERE [ID] =?数据文件=_私/ records.mdb的SelectCommand =SELECT * FROM [PendingRecords]>
        < D​​eleteParameters>
            < ASP:参数名称=ID类型=的Int32/>
        < / DeleteParameters>
        < UpdateParameters>
            < ASP:参数名称=用户名类型=字符串/>
            < ASP:参数名称=密码类型=字符串/>
            < ASP:参数名称=名字类型=字符串/>
            < ASP:参数名称=姓氏类型=字符串/>
            < ASP:参数名称=中间名类型=字符串/>
            < ASP:参数名称=地址类型=字符串/>
            < ASP:参数名称=性别类型=字符串/>
            < ASP:参数名称=ContactNumber类型=字符串/>
            < ASP:参数名称=PlateNumber类型=字符串/>
            < ASP:参数名称=颜色类型=字符串/>
            < ASP:参数名称=品牌TYPE =字符串/>
            < ASP:参数名称=LiscensedNumber类型=字符串/>
            < ASP:参数名称=ID类型=的Int32/>
        < / UpdateParameters>
        < InsertParameters>
            < ASP:参数名称=用户名类型=字符串/>
            < ASP:参数名称=密码类型=字符串/>
            < ASP:参数名称=名字类型=字符串/>
            < ASP:参数名称=姓氏类型=字符串/>
            < ASP:参数名称=中间名类型=字符串/>
            < ASP:参数名称=地址类型=字符串/>
            < ASP:参数名称=性别类型=字符串/>
            < ASP:参数名称=ContactNumber类型=字符串/>
            < ASP:参数名称=PlateNumber类型=字符串/>
            < ASP:参数名称=颜色类型=字符串/>
            < ASP:参数名称=品牌TYPE =字符串/>
            < ASP:参数名称=LiscensedNumber类型=字符串/>
        < / InsertParameters>
    < / ASP:&的AccessDataSource GT;

下面是UploadPhoto.aspx页面code为btnUpload_Click:

 <脚本=服务器类型=文/ C#>
保护无效btnUpload_Click(对象发件人,EventArgs的发送)
{
    {
   字节[] = IMAGESIZE新字节
                 [FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read
     (IMAGESIZE,0,(int)的FileUpload1.PostedFile.ContentLength);
 //创建SQL连接
  OleDbConnection的CON =新的OleDbConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings [recordsConnectionString12]的ConnectionString。
 //创建SQL命令
 OleDbCommand的CMD =新的OleDbCommand();
 cmd.CommandText =INSERT INTO PendingRecords([图片])+VALUES(@Image);
 cmd.CommandType = CommandType.Text;
 cmd.Connection = CON; OleDbParameter UploadedImage =新OleDbParameter
              (@Image,OleDbType.VarBinary,imageSize.Length); UploadedImage.Value = IMAGESIZE;
 cmd.Parameters.Add(UploadedImage);
 con.Open();
 cmd.ExecuteNonQuery();
 GridView1.DataSourceID =;
 GridView1.DataSource = SqlDataSource1;
 GridView1.DataBind();
 con.Close();
 }
}
< / SCRIPT>

UploadPhoto.aspx页DATASOURCE code:

 < ASP:SqlDataSource的=服务器ID =SqlDataSource1的ProviderName =<%$的ConnectionStrings:recordsConnectionString12.ProviderName%>中的ConnectionString =下;%$的ConnectionStrings:recordsConnectionString12%>中的SelectCommand =SELECT * FROM [PendingRecords]的DeleteCommand =删除[PendingRecords] WHERE [ID] =?将InsertCommand =INSERT INTO [PendingRecords]([用户名],[密码],[名字],[姓氏],[中间名],[地址],[两性],[ContactNumber],[PlateNumber],[颜色],[品牌],[LiscensedNumber])VALUES(?,?,?,?,?,?,?,?,?,?,?,?)的UpdateCommand =UPDATE [PendingRecords] SET [用户名] = [密码] =?,[名字] = [姓氏] = [中间名] = [地址] = [两性] =?[ContactNumber] =?[PlateNumber] =?[颜色] = ?[品牌] = [LiscensedNumber] = WHERE [ID] =&GT??;
    < D​​eleteParameters>
        < ASP:参数名称=ID类型=的Int32/>
    < / DeleteParameters>
    < UpdateParameters>
        < ASP:参数名称=用户名类型=字符串/>
        < ASP:参数名称=密码类型=字符串/>
        < ASP:参数名称=名字类型=字符串/>
        < ASP:参数名称=姓氏类型=字符串/>
        < ASP:参数名称=中间名类型=字符串/>
        < ASP:参数名称=地址类型=字符串/>
        < ASP:参数名称=性别类型=字符串/>
        < ASP:参数名称=ContactNumber类型=字符串/>
        < ASP:参数名称=PlateNumber类型=字符串/>
        < ASP:参数名称=颜色类型=字符串/>
        < ASP:参数名称=品牌TYPE =字符串/>
        < ASP:参数名称=LiscensedNumber类型=字符串/>
        < ASP:参数名称=ID类型=的Int32/>
    < / UpdateParameters>
    < InsertParameters>
        < ASP:参数名称=用户名类型=字符串/>
        < ASP:参数名称=密码类型=字符串/>
        < ASP:参数名称=名字类型=字符串/>
        < ASP:参数名称=姓氏类型=字符串/>
        < ASP:参数名称=中间名类型=字符串/>
        < ASP:参数名称=地址类型=字符串/>
        < ASP:参数名称=性别类型=字符串/>
        < ASP:参数名称=ContactNumber类型=字符串/>
        < ASP:参数名称=PlateNumber类型=字符串/>
        < ASP:参数名称=颜色类型=字符串/>
        < ASP:参数名称=品牌TYPE =字符串/>
        < ASP:参数名称=LiscensedNumber类型=字符串/>
    < / InsertParameters>
< / ASP:SqlDataSource的>


解决方案

您需要从个人信息页的ID传递到上传页面(可能通过查询字符串)。

和然后更新您的图片应该和UPDATE查询查询,请参阅下文。

  cmd.CommandText =UPDATE PendingRecords SET [图片] = @Image WHERE ID = @ID;

您现在要传递的ID参数需要。

如果该参数在查询字符串(/Uplo​​adPhoto.aspx?id=60)

  OleDbParameter UploadedImage =新OleDbParameter
              (@Image,OleDbType.VarBinary,imageSize.Length); UploadedImage.Value = IMAGESIZE;
 cmd.Parameters.Add(UploadedImage);OleDbParameter IdParameter =新OleDbParameter(@ ID的Request.QueryString [身份证]);
    cmd.Parameters.Add(IdParameter);

I'M GOING TO ASK THIS FOR THE SECOND TIME. I'M GOING TO MAKE IT CLEAR SO YOU CAN HELP ME :) Okay let's start.

I have a Registration Process. I split the process into two page. The first page is for "Personal Information" only. Then when i click the next button the next page will appear (postbackURL) This page is for "Upload Photo" page. They work fine! the data and the image are displayed on my gridview control. But my problem is here: As you can see in the figure below. The data are populated in two rows! I want them to appear in only single row! I think the problem is THE DATABASE FROM PAGE 1 IS NOT CONTINUING. THAT'S WHY WHEN I UPLOAD AN IMAGE IN PAGE 2 THE DATABASE WILL CREATE ANOTHER RECORD. hmmm...what's the problem :) I don't know how to do it. Please help!

THE DATA SHOWN IN THE TABLE BELOW ARE ONLY DUMMY. PLEASE DON'T TAKE IT SERIOUSLY.

Here's the code for INSERT/UPDATE for PersonalINFO.aspx page:

<asp:AccessDataSource runat="server" ID="AccessDataSource1" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ? WHERE [ID] = ?" DataFile="_private/records.mdb" SelectCommand="SELECT * FROM [PendingRecords]">
        <DeleteParameters>
            <asp:parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:parameter Name="Username" Type="String" />
            <asp:parameter Name="Password" Type="String" />
            <asp:parameter Name="FirstName" Type="String" />
            <asp:parameter Name="LastName" Type="String" />
            <asp:parameter Name="MiddleName" Type="String" />
            <asp:parameter Name="Address" Type="String" />
            <asp:parameter Name="Gender" Type="String" />
            <asp:parameter Name="ContactNumber" Type="String" />
            <asp:parameter Name="PlateNumber" Type="String" />
            <asp:parameter Name="Color" Type="String" />
            <asp:parameter Name="Brand" Type="String" />
            <asp:parameter Name="LiscensedNumber" Type="String" />
            <asp:parameter Name="ID" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:parameter Name="Username" Type="String" />
            <asp:parameter Name="Password" Type="String" />
            <asp:parameter Name="FirstName" Type="String" />
            <asp:parameter Name="LastName" Type="String" />
            <asp:parameter Name="MiddleName" Type="String" />
            <asp:parameter Name="Address" Type="String" />
            <asp:parameter Name="Gender" Type="String" />
            <asp:parameter Name="ContactNumber" Type="String" />
            <asp:parameter Name="PlateNumber" Type="String" />
            <asp:parameter Name="Color" Type="String" />
            <asp:parameter Name="Brand" Type="String" />
            <asp:parameter Name="LiscensedNumber" Type="String" />
        </InsertParameters>
    </asp:AccessDataSource>

Here's the code for btnUpload_Click in UploadPhoto.aspx page:

<script runat="server" type="text/c#">
protected void btnUpload_Click(object sender, EventArgs e)


{
    {
   byte[] imageSize = new byte
                 [FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read
     (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
 // Create SQL Connection
  OleDbConnection con = new OleDbConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings["recordsConnectionString12"].ConnectionString;
 // Create SQL Command
 OleDbCommand cmd = new OleDbCommand();
 cmd.CommandText = "INSERT INTO PendingRecords([Image])" + " VALUES (@Image)";
 cmd.CommandType = CommandType.Text;
 cmd.Connection = con;

 OleDbParameter UploadedImage = new OleDbParameter
              ("@Image", OleDbType.VarBinary, imageSize.Length);

 UploadedImage.Value = imageSize;
 cmd.Parameters.Add(UploadedImage);
 con.Open();
 cmd.ExecuteNonQuery();
 GridView1.DataSourceID = "";
 GridView1.DataSource = SqlDataSource1;
 GridView1.DataBind();
 con.Close();
 }
}
</script>

UploadPhoto.aspx page DATASOURCE CODE:

<asp:SqlDataSource runat="server" id="SqlDataSource1" ProviderName="<%$ ConnectionStrings:recordsConnectionString12.ProviderName %>" ConnectionString="<%$ ConnectionStrings:recordsConnectionString12 %>" SelectCommand="SELECT * FROM [PendingRecords]" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ? WHERE [ID] = ?">
    <DeleteParameters>
        <asp:parameter Name="ID" Type="Int32" />
    </DeleteParameters>
    <UpdateParameters>
        <asp:parameter Name="Username" Type="String" />
        <asp:parameter Name="Password" Type="String" />
        <asp:parameter Name="FirstName" Type="String" />
        <asp:parameter Name="LastName" Type="String" />
        <asp:parameter Name="MiddleName" Type="String" />
        <asp:parameter Name="Address" Type="String" />
        <asp:parameter Name="Gender" Type="String" />
        <asp:parameter Name="ContactNumber" Type="String" />
        <asp:parameter Name="PlateNumber" Type="String" />
        <asp:parameter Name="Color" Type="String" />
        <asp:parameter Name="Brand" Type="String" />
        <asp:parameter Name="LiscensedNumber" Type="String" />
        <asp:parameter Name="ID" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
        <asp:parameter Name="Username" Type="String" />
        <asp:parameter Name="Password" Type="String" />
        <asp:parameter Name="FirstName" Type="String" />
        <asp:parameter Name="LastName" Type="String" />
        <asp:parameter Name="MiddleName" Type="String" />
        <asp:parameter Name="Address" Type="String" />
        <asp:parameter Name="Gender" Type="String" />
        <asp:parameter Name="ContactNumber" Type="String" />
        <asp:parameter Name="PlateNumber" Type="String" />
        <asp:parameter Name="Color" Type="String" />
        <asp:parameter Name="Brand" Type="String" />
        <asp:parameter Name="LiscensedNumber" Type="String" />
    </InsertParameters>
</asp:SqlDataSource>
解决方案

You will need to pass the ID from personal info page to the Upload page (probably via query string).

And then the query for your image update should be and UPDATE query, see below.

cmd.CommandText = "UPDATE PendingRecords SET [Image] = @Image WHERE ID = @ID";

You'll now pass in the ID parameter as needed.

If the parameter is in the query string ( /UploadPhoto.aspx?id=60 )

OleDbParameter UploadedImage = new OleDbParameter
              ("@Image", OleDbType.VarBinary, imageSize.Length);

 UploadedImage.Value = imageSize;
 cmd.Parameters.Add(UploadedImage);

OleDbParameter IdParameter = new OleDbParameter("@ID", Request.QueryString["id"]);
    cmd.Parameters.Add(IdParameter);

这篇关于数据和图像填充在两行。我想将它们绑定在一个单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 17:53
查看更多