ciao non capisco dove sbaglio .
il codice fa l 'upload del file con miniature e qui bene , pero se aggiungo quel codice per la registrazione nel database mi da errore.

ovviamente è tutto racchiuso in un ciclo perche i file possono essere piu di uno ... fa parte di un upload multiplo


<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" Debug="true" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Data" %>


<script runat="server">
//This variable specifies relative path to the folder, where the gallery with uploaded files is located.
//Do not forget about the slash in the end of the folder name.
private string galleryPath = "../../../public/";

private void Page_Load(System.Object sender, System.EventArgs e)
{
string realGalleryPath = Request.Form["TargetFolder"];

string realcategoriaPath = Request.Form["Targetcategoria"];











//First of all, clear files and data uploaded at previous time.

//Delete source files.

//Delete thumbnails.
//NOTE: If you do not want to delete previously uploaded files, just
//remove or comment out the code above.

//Create XML file which will keep information about files (image dimensions, description, etc).
//XML is used solely for brevity. In real-life application most likely you will use database instead.
XmlDocument descriptions = new XmlDocument();
descriptions.AppendChild(descriptions.CreateElemen t("files"));

//Get total number of uploaded files (all files are uploaded in a single package).
int fileCount = Int32.Parse(Request.Form["FileCount"]);

//Iterate through uploaded data and save the original file, thumbnail, and description.



for (int i = 1; i <= fileCount; i++)
{
//Get source file and save it to disk.
HttpPostedFile sourceFile = Request.Files["SourceFile_" + i];
string fileName = realcategoriaPath + GetSafeFileName(Path.GetFileName(sourceFile.FileNa me));
sourceFile.SaveAs(Server.MapPath(realGalleryPath + fileName));

//Get first thumbnail (the single thumbnail in this code sample) and save it to disk.
HttpPostedFile thumbnail1File = Request.Files["Thumbnail1_" + i];
thumbnail1File.SaveAs(Server.MapPath(realGalleryPa th + fileName + "_t.jpg"));

//------------------------inserimento in database---------------------------------------


Dim objConn As IDbConnection = "Driver={MySQL ODBC 3.51 Driver}; server=127.0.0.1; PORT=3306; uid=root; pwd=david; database=gallery;";

Dim chkUsername As IDbCommand
Dim addUser As IDbCommand
Dim strSQL1 As String
Dim strSQL2 As String
Dim strUserCount As Integer



strSQL2 = "INSERT INTO [fotoprivate] ([nomefoto])"
strSQL2 = strSQL2 & " VALUES "
strSQL2 = strSQL2 & "('" & fileName & "');"

objConn.Open()

addUser = New OleDbCommand(strSQL2, objCOnn)
addUser.ExecuteNonQuery()
objConn.Close











// using (OdbcConnection conn = new OdbcConnection(connString))





//Save file info.
XmlElement xmlFile = descriptions.CreateElement("file");
xmlFile.SetAttribute("name", fileName);
xmlFile.SetAttribute("width", Request.Form["Width_" + i]);
xmlFile.SetAttribute("height", Request.Form["Height_" + i]);
xmlFile.SetAttribute("description", Request.Form["Description_" + i]);

descriptions.DocumentElement.AppendChild(xmlFile);
}

descriptions.Save(Server.MapPath(realGalleryPath + "Descriptions.xml"));
}

//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
private string GetSafeFileName(string fileName)
{
string newFileName = fileName;
int j = 1;
while (File.Exists(Server.MapPath(galleryPath + newFileName)))
{
newFileName = j + "_" + fileName;
j++;
}
return newFileName;
}
</script>