Thanks for the quick response jmeckley. Actually I am using .NET2.0 so I can use the fileUpload control which eliminates the stream to a file. I am having success uploading the file to a folder. I can also insert my form field to a DB. I just haven't been able to combine the two - I suppose because of the fileupload control.
Here's what I have so far:
The form page:
<form id="form1" runat="server">
<input id="estabid" type="hidden" value='xxxx'/>
<b>Title</b>
<br />
<asp:TextBox ID="title" runat="server">Enter Title Here</asp:TextBox>
<br />
<b>Image</b>
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<p>
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
</form>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
InsertCommand="INSERT INTO dbo.upload_images(title) VALUES (@title)"
SelectCommand="SELECT [id], [estabid], [title] FROM [upload_images] ORDER BY [estabid]">
<InsertParameters>
<asp:ControlParameter ControlID="title" Name="title" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
and the code behind:
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try {
FileUpload1.SaveAs("C:\\uploader\\images\\" +
FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
//SqlDataSource1.Insert(); THIS Doesn't work
}
catch (Exception ex) {
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
}
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
if (e.Exception != null)
{
Response.Write(e.Exception.Message);
Response.End();
}
}
</script>