سلام
وقتی میخوام رکورد جدید به جدول اضافه کنم خطا میده و از برنامه میپره بیرون
LINQdataDataContext dc = new LINQdataDataContext();
private void btnadd_Click(object sender, EventArgs e)
{
famil2 tb = new famil2();
tb.name = txtfirstname.Text;
tb.famil = txtlastname.Text;
tb.father = txtfathername.Text;
dc.famil2s.InsertOnSubmit(tb);
dc.SubmitChanges();
dataGridView1.DataSource = dc.famil2s.ToList();
}
خطایی که میده عنوانش اینه System.InvalidOperationException
متن خطا
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.Linq.dll
Additional information: Can't perform Create, Update, or Delete operations on 'Table(famil2)' because it has no primary key.
ممنون میشم راهنمایی کنین
visual studio 2015
sql server 2016
متن خطا را ضمیمه کنید
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Can't perform Create, Update, or Delete operations on 'Table(famil2)' because it has no primary key.
Source=System.Data.Linq
StackTrace:
at System.Data.Linq.Table`1.CheckReadOnly()
at System.Data.Linq.Table`1.InsertOnSubmit(TEntity entity)
at formfamilLINQ.Form1.btnadd_Click(Object sender, EventArgs e) in c:\users\hoseinjp\documents\visual studio 2015\Projects\formfamilLINQ\formfamilLINQ\Form1.cs:line 47
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at formfamilLINQ.Program.Main() in c:\users\hoseinjp\documents\visual studio 2015\Projects\formfamilLINQ\formfamilLINQ\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
چک کنید جدول حتما کلید اصلی داشته باشد
و همینطور Auto Incerement باشد
بعله درست شد تشکر
اما آیا نمیشه جدولم کلید اصلی نداشته باشه؟
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)