0

MVC4 ビジュアル スタジオを使用してプロジェクトを作成します。私がやろうとしているのは、モデルのデータベースへのSQL命令「Insert Into」です。

以下のコードがありますが、「メソッドには戻り値の型が必要です」というエラーが表示されます。

何を書けばいいのかわからない..

エラー: infouploadimage に赤い下線があります

誰かが私にこれを手伝ってくれますか?

モデル内のコード:

 public class UploadImage
     {
         public string Title { get; set; }
         public string ImagePath { get; set; }

         public infouploadimage(string title, string imagepath) 
         {
             Title=title;
             ImagePath=imagepath;

             string connection = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

             using (SqlConnection connect = new SqlConnection(connection))
             {
                 string query = "Insert Into myimage (PicTitle, PicPath) Values(@title, @imagepath)";

                 SqlCommand command = new SqlCommand(query, connect);
                 command.Parameters.AddWithValue("title", Title);
                 command.Parameters.AddWithValue("imagepath", ImagePath);
                 connect.Open();
                 command.ExecuteNonQuery();
             } 


         }
     }
4

3 に答える 3

3

このメソッドには、明らかにその定義の一部 (voidこの場合は戻り値の型) が欠けています。

public void infouploadimage(string title, string imagepath)
于 2013-07-26T09:00:59.577 に答える
1

宣言にエラーがあります:

     public infouploadimage(string title, string imagepath) 
     {

次のようなものを使用して修正できます。

     public void infouploadimage(string title, string imagepath) 
     {
于 2013-07-26T09:01:37.650 に答える
1

あなたが試したのは ではないためconstructor、戻り値の型がありません。不要な場合は、次のように設定してvoidください。

public void infouploadimage(string title, string imagepath)
于 2013-07-26T09:01:13.313 に答える