2013-04-04 44 views
0

我完成程序並開始工作後,我用sql數據庫做了一個C#程序,
我想將其中一個列類型從int更改爲nvarchar(50),知道數據庫已經充滿了數據。如何更改Visual Studio中的SQL列類型C#

我將表列類型更改爲nvarchar(50),並在數據集上將其更改爲System.String。
運行程序後,它給了我這個異常

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box. 

************** Exception Text ************** 
System.FormatException: Failed to convert parameter value from a String to a Int32. ---> System.FormatException: Input string was not in a correct format. 
    at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) 
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) 
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
    at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType, Boolean& coercedToDataFeed, Boolean& typeChanged, Boolean allowStreaming) 
    --- End of inner exception stack trace --- 
    at Tiryaq.TiryaqDatabaseDataSetTableAdapters.TableAdapterManager.UpdateAll(TiryaqDatabaseDataSet dataSet) in C:\Users\Firas\Documents\Visual Studio 2010\Projects\Tiryaq\Tiryaq\TiryaqDatabaseDataSet.Designer.cs:line 1973 
    at Tiryaq.Form1.medicinTableBindingNavigatorSaveItem_Click(Object sender, EventArgs e) in C:\Users\Firas\Documents\Visual Studio 2010\Projects\Tiryaq\Tiryaq\Form1.cs:line 31 
    at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) 
    at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) 
    at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ToolStrip.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

謝謝。

UPDATE:其實點擊保存按鈕
這裏當異常上升的方法

private void medicinTableBindingNavigatorSaveItem_Click(object sender, EventArgs e) 
     { 

      { 
       this.Validate(); 
       this.medicinTableBindingSource.EndEdit(); 
       this.tableAdapterManager.UpdateAll(this.tiryaqDatabaseDataSet); 
      } 
     } 
+0

你刷新了數據集嗎? 'TiryaqDatabaseDataSet'? – 2013-04-04 01:47:50

+0

我不確定,怎麼做? – 2013-04-04 01:48:42

+0

嘗試打開它並右鍵單擊打開區域的某處,查看是否有刷新模式的選項。 – 2013-04-04 01:49:57

回答

0

最後我發現,
改變數據庫和數據集的類型後,我必須打開Datasetname.Designer.cs並查找所有column_name values並將它們更改爲string,因爲在更改數據庫和數據集中的類型後,並不是所有代碼都會更改。
謝謝你們的幫助。