2016-09-28 44 views
0

データが保存された後にエラーが表示されます。指定されたパス形式はサポートされていません。何か問題があったか、url間違った場所?エラーSystem.NotSupportedException:指定されたパスの形式がサポートされていません

try 
{ 
    connect.Open(); 
    OleDbCommand command = new OleDbCommand(); 
    command.Connection = connect; 
    command.CommandText = string.Format("insert into RegisterItem([Name], [Url],[Description], [Price]) values('{0}','{1}','{2}','{3}')", 
             ItemName.Text, 
             ItemUrl.Text, 
             ItemDescription.Text, 
             ItemPrice.Text); 

    command.ExecuteNonQuery(); 
    MessageBox.Show("Data Saved"); 

    txtID1.Text = txtUsername.Text; 
    txtName1.Text = ItemName.Text; 
    txtDescription1.Text = ItemDescription.Text; 
    txtPrice1.Text = ItemPrice.Text; 
    ItemName.Text = ""; 
    ItemDescription.Text = ""; 
    ItemPrice.Text = ""; 
    string str = ItemUrl.Text; 
    pictureBox1.ImageLocation = str; 
    string str1 = textBox1.Text; 
    Image img = Image.FromFile(str); 
    pictureBox1.Image = img; 
} 
catch (Exception ex) 
{ 
    MessageBox.Show("Error " + ex); 
} 
finally 
{ 
    if (Connect != null) { connect.Close(); } 
} 
+1

'ItemUrl'には何がありますか?私たちはあなたのコンピュータを見ることができません:) – Pikoh

+0

それはテキストボックスです、あなたはURLを入力し、画像はpictureBox1にロードされます –

+1

しかし、例外を引き起こす 'ItemUrl.Text'値は何ですか? – slawekwin

答えて

1

それは問題になる

 Image img = Image.FromFile(str); 

です。 URLからイメージを読み込むことはできませんが、ファイルパスでなければなりません。

 WebRequest wr = WebRequest.Create("https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg"); 
     Image img; 
     using (var rs = wr.GetResponse().GetResponseStream()) 
     { 
      img = Image.FromStream(rs); 
     } 

にあなたが持っているURLからイメージをロードするために実際に、あなたは完全に

Image img = Image.FromFile(str); 
pictureBox1.Image = img; 

を省略することができ、コードのこの部分は、正確に、すべてのジョブ

pictureBox1.ImageLocation = str; 

を行いますImage.FromFileはディスクファイルからのみ読み込みますが、ImageLocationを設定するとurlから読み込むことができ、同時にd生地とキャンバスへの画像

+0

本当に?私は他のコードを変更する前に、これは正常に動作します、それは直接リンクのURLを入れている間に読み込みます –

+0

この方法はとにかく動作するのですか? postimage.orgのようなウェブサイトから変換した後に直接リンクで読み込まれます –

+0

C:\ Users \ Teronkee \ Pictures \ 98b288f6-e204-40fe-a4f3-cb83a21f4be3.jpgのようなファイルパスのリンクが入力された直後に画像を読み込む方法はありますか?私が使用したメソッドはブラウズ機能でのみサポートされています –

関連する問題