0

コードを Visual Studio 2010 から 2012 に移行し、すべてが期待どおりに動作することを確認しています。この移行中に、テーブルの 1 つにデータを挿入しようとすると、LINQ-to-SQL サンプル プログラムが失敗します。以下は、ユーザーが保存ボタンをクリックしたときのコードです。

public class DebugTextWriter : TextWriter
{
    public override void Write(char[] buffer, int index, int count)
    {
        Debug.Write(new String(buffer, index, count));
    }
    public override void Write(string value)
    {
        Debug.Write(value);
    }
    public override Encoding Encoding
    {
        get
        {
            return Encoding.Default;
        }
    }
}

private void SaveButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            //First we locate the 'orderViewSource' object that the user filled in
              CollectionViewSource orderViewSource =
              FindResource("orderViewSource") as CollectionViewSource;

            //Next we save the values entered in into a generic list (only 1 entry 
              here)
            List<Order> ordList = orderViewSource.Source as List<Order>;

            //Again, since there is only one entry, we take it and fill in a new row in
            //our 'Order' table
            Order ord = ordList.FirstOrDefault();

            //In order for the insert to work, you need to create an instance of the
            //LINQ to SQL class for that table and then call the insert method on the
            //'ord' container and then finally submit it.
            var ctx = new MyShopDataContext();
            ctx.Orders.InsertOnSubmit(ord);
            ctx.SubmitChanges();
            MessageBox.Show("Order Saved!");
        }
        catch (Exception)
        {
        }
    }

私のコードはエラーなしでビルドされ、例外はスローされません。このコードが機能しない理由について何か考えはありますか?

4

1 に答える 1

0

この質問に対する私の誤り...私はもっとよく知っているべきでした: このウェブサイトを適切に調査した後、次のエラー解決策を見つけました:

「自動命名データベースを接続しようとしています」エラー

投稿してくれたすべての人に感謝します

于 2013-06-22T13:32:10.633 に答える