I'm writing an application in c# using wpf and i was wondering how do you create a data table in wpf? This is a really dumb question, i'm aware, but it doesn't appear like i'm using the correct references as the data table object never appears when i try to create it. My references are as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Linq;
using System.ComponentModel;
using System.Data.Sql;
Here's a method that creates a DataTable...
private void CreateDataTable()
{
System.Data.DataTable dt = new DataTable("MyTable");
dt.Columns.Add("MyColumn", typeof (string));
dt.Rows.Add("row of data");
}
The relevant assembly (as identified by HighCore in the commentary) is System.Data. If it is not included in your references, you can add it via the 'add reference' context menu.
Related
I want to pass a textbox value to RDLC report. For said purpose my code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WebForms;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
using System.Globalization;
ReportParameterCollection reportParameters = new ReportParameterCollection();
reportParameters.Add(new ReportParameter("ReportParameter1", t1.Text));
this.reportViewer2.LocalReport.SetParameters(reportParameters);
this.reportViewer2.RefreshReport();
But i get the error during compile time which is:
Error 15 The best overloaded method match for 'Microsoft.Reporting.WinForms.Report.SetParameters(System.Collections.Generic.IEnumerable<Microsoft.Reporting.WinForms.ReportParameter>)' has some invalid arguments
Error 16 Argument 1: cannot convert from 'Microsoft.Reporting.WebForms.ReportParameterCollection' to 'System.Collections.Generic.IEnumerable<Microsoft.Reporting.WinForms.ReportParameter>'
This error occurs on following line:
this.reportViewer2.LocalReport.SetParameters(reportParameters);
Help is required to resolve it. Thanks in advance
I resolved the error by replacing Microsoft.Reporting.WebForms with Microsoft.Reporting.WinForms
I'm not experienced with C#, but I got the basics down. Now I'm trying to download videos from YouTube with the Video Library (in the VS package manager: Install-Package VideoLibrary).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using VideoLibrary;
namespace TubeDemo
{
public partial class MainWindow : Window
{
string link = "https://www.youtube.com/watch?v=8SbUC-UaAxE";
string link2 = "https://www.youtube.com/watch?v=BlRqTNkgEuo";
public MainWindow()
{
InitializeComponent();
}
void SaveVideoToDisk_Click(object sender, EventArgs e)
{
var youTube = YouTube.Default; // starting point for YouTube actions
var video = youTube.GetVideo(link2); // gets a Video object with info about the video
File.WriteAllBytes(#"C:\testfire\" + video.FullName, video.GetBytes());
}
}
}
Above functions SaveVideoToDisk_Click gets called from a .xaml button, which works fine. But not every video works OK. video.URI gets awfully big, over 800 characters. Some of the URLs turn out to cause the video.URI to throw an exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
In the code provided, passing link as argument throws while passing link2 works just fine.
Can I fix this?
If not, how should I handle these exceptions? Just try, catch and report or is checking before a better idea?
I have a strange error and don't know how to solve that. I have a Form which gets opened by another (Main)Form. When I write
List<String> valStoreAsString = new List<String>();
I get "The value or namespace List could not get found". My using directives are the following:
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Runtime.InteropServices;
In the other Forms it works fine. What happened here?
Add following using directive to the list of usings.
using System.Collections.Generic;
Tip
If you are using Visual Studio and if you don't know the namespace then type name of type (Case sensetive) in editor and then press ctrl+ . and select add using option and VS will add related using for you.
or you can right click on name of Type and select Resolve option and select using .... sub option.
What is the assembly reference for a Filedownloader in c#?
I am looking for to download the files from ftp to my local drive 'c' ,
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
FileDownloader f = new FileDownloader();
which reference should I need to add for the filedownloader?
I guess that you are trying to download files from FTP,and you don't have to use the FileDownloader class.
You can use this link for example: "http://msdn.microsoft.com/en-us/library/ms229711(v=vs.110).aspx".
You can also use an open source to do that, try looking at this link: "http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class"
There is an example of how simple it is to use (From the link above):
ftp ftpClient = new ftp(#"ftp://10.10.10.10/", "user", "password");
ftpClient.download("etc/test.txt", #"C:\Users\metastruct\Desktop\test.txt");
I have a problem with RenderMode-property of the ToolStripSeparator.
When I put the following line of code :
this.toolStripSeparator1.RenderMode = ToolStripRenderMode.System;
I have the following error :
error 44 'System.Windows.Forms.ToolStripSeparator' does not contain a
definition for 'RenderMode' and no extension method 'RenderMode'
accepting a first argument of type
'System.Windows.Forms.ToolStripSeparator' could be found (are you
missing a using directive or an assembly reference?)
Despite, I put the references
using System.Windows.Forms;
Below is a list of my references
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Diagnostics;
Do you have any ideas what could cause this error?
ToolStripRenderMode Enumeration's value can be assigned to RenderMode property of ToolStrip.
ToolStripSeparator donot have any such property.
I think you should use it like this:
toolStrip1.RenderMode=ToolStripRenderMode.System;