I have three files one is class filedownload.cs in which i have three functions...GetFileLIST() savefile() and GetaFile().second file is GetFile.aspx and third is form in which code is behind button.using all these files i am uploading a file and showing in gridview and it is working for me.but now i have another form in which i want to use the code for uploading file.but for another form i have to repeat all these code because of query because i have differet table now...
please resolve this problem to make my code short and not to repeat....
filedownload.cs
public static DataTable GetFileList()
{
DataTable dt=new DataTable();
using (SqlConnection con = new SqlConnection())
{
OpenConnection(con);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandTimeout = 0;
com.CommandText = "SELECT ID, Name, [Content], size FROM Connectivity";
com.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = com;
da.Fill(dt);
con.Close();
}
return dt;
}
public static void savefile(string name, string content, int size, byte[] data)
{
using (SqlConnection con = new SqlConnection())
{
OpenConnection(con);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandTimeout = 0;
string ct = "INSERT INTO Connectivity VALUES (@name,@content,";
ct = ct + "@size,@data)";
com.CommandText = ct;
com.CommandType = CommandType.Text;
com.Parameters.Add("@name", SqlDbType.VarChar, 50);
com.Parameters.Add("@content", SqlDbType.VarChar, 50);
com.Parameters.Add("@size", SqlDbType.Int);
com.Parameters.Add("@data", SqlDbType.VarBinary);
com.Parameters["@Name"].Value = name;
com.Parameters["@content"].Value = content;
com.Parameters["@size"].Value = size;
com.Parameters["@data"].Value = data;
com.ExecuteNonQuery();
con.Close();
}
}
public static DataTable Getafile(int id)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection())
{
OpenConnection(con);
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandTimeout = 0;
com.CommandText = "SELECT ID, Name, [Content], size, data FROM Connectivity where ID=@ID";
com.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
com.Parameters.Add("@ID", SqlDbType.Int);
com.Parameters["@ID"].Value = id;
da.SelectCommand = com;
da.Fill(dt);
con.Close();
}
return dt;
}
/