Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
Populate listview with VARBINARY(MAX) variable
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Dealy
10y
1.1k
1
Reply
Hello,
I'm trying to populate data from SQL Server into a listview. This is my code in C#:
public void downloadFiles(SqlConnection conn, String sproc, ListView listView, int parentId)
{
SqlCommand command = new SqlCommand(sproc, conn);
command.Parameters.Add(new SqlParameter("@ParentId", parentId));
command.CommandType = CommandType.StoredProcedure;
SqlDataReader rd = null;
conn.Open();
rd = command.ExecuteReader();
while (rd.Read())
{
byte[] b = (byte[])rd["DocPath"];
FileStream fs = new FileStream(rd["DocSubject"].ToString(), FileMode.Create);
fs.Write(b, 0, b.Length);
StreamWriter sw = new StreamWriter(fs);
ListViewItem item = new ListViewItem(rd["ParentId"].ToString());
for (int i = 1; i <= rd.FieldCount - 1; i++)
{
item.SubItems.Add(rd["DocSubject"].ToString());
item.SubItems.Add(rd["DocName"].ToString());
item.SubItems.Add(rd["DocFileFormat"].ToString());
sw.WriteLine(item.SubItems.Add(rd["DocSubject"].ToString()));
sw.Flush();
sw.Close();
}
listView.Items.Add(item);
}
rd.Close();
conn.Close();
}
The problem is that I need DocPath (VARBINARY(MAX) variable) to be populated on column DocPath of the listView as a download link.
I would appreciate any kind of help.
Thank you in advance.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
Enter key navigation in windows form
Play the buzzer continuosly until stopped by the user