我要第二次问这个问题。我要让它变得清晰,所以你可以帮助我:)好的,让我们开始吧。
我有注册程序。我把这个过程分成了两页。第一页仅用于“个人信息”。然后,当我单击下一个按钮时,将出现下一页(postbackURL)此页面用于“上载照片”页面。他们工作正常!数据和图像显示在我的gridview控件上。但我的问题在于:如下图所示。数据分为两行!我希望它们只出现在一排!我认为问题是第1页的数据库不是在继续。这就是为什么我在第2页上传图像数据库会创建另一个记录。嗯...问题是什么:)我不知道怎么做。请帮忙!
下表中显示的数据仅为DUMMY。请不要严肃对待。
以下是PersonalINFO.aspx页面的INSERT / UPDATE代码:
<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>
以下是UploadPhoto.aspx页面中btnUpload_Click的代码:
<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页面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>
答案 0 :(得分:2)
您需要将ID从个人信息页面传递到上传页面(可能通过查询字符串)。
然后查询您的图片更新应该是UPDATE查询,见下文。
cmd.CommandText = "UPDATE PendingRecords SET [Image] = @Image WHERE ID = @ID";
现在,您将根据需要传入ID参数。
如果参数在查询字符串中(/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);