C# 从数据库中删除,插入,修改 索引选中条目

前端之家收集整理的这篇文章主要介绍了C# 从数据库中删除,插入,修改 索引选中条目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一。删除

1.

(usrListView.SelectedIndex != - currentSelectIndex = item = (StockManageDataContext smDataContext = Box.Show(ex.Message); } } }

2.

MenuItemDelete_Click( </span><span style="color: #0000ff;"&gt;if</span> (AddressList.SelectedIndex == -<span style="color: #800080;"&gt;1</span><span style="color: #000000;"&gt;) { Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(</span><span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;请选择一项!</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;); </span><span style="color: #0000ff;"&gt;return</span><span style="color: #000000;"&gt;; } </span><span style="color: #0000ff;"&gt;if</span> (Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;确认<a href="https://www.jb51.cc/tag/shanchu/" target="_blank" class="keywords">删除</a>所选定的供应商信息?</span><span style="color: #800000;"&gt;"</span>,<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;<a href="https://www.jb51.cc/tag/tishi/" target="_blank" class="keywords">提示</a></span><span style="color: #800000;"&gt;"</span>,Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>Button.OKCancel) ==<span style="color: #000000;"&gt; Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>Result.OK) { </span><span style="color: #0000ff;"&gt;while</span> (AddressList.SelectedIndex != -<span style="color: #800080;"&gt;1</span><span style="color: #000000;"&gt;){ </span><span style="color: #0000ff;"&gt;var</span> currentSelectIndex =<span style="color: #000000;"&gt; AddressList.SelectedIndex; SHDZ selectedAddress </span>=<span style="color: #000000;"&gt; (SHDZ)AddressList.SelectedValue; </span><span style="color: #0000ff;"&gt;using</span> (WJKCDataContext wjkc = <span style="color: #0000ff;"&gt;new</span><span style="color: #000000;"&gt; WJKCDataContext()) { </span><span style="color: #0000ff;"&gt;try</span><span style="color: #000000;"&gt; { wjkc.ExecuteCommand(</span><span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;DELETE FROM SHDZ WHERE CODE={0}</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;,selectedAddress.CODE); addressView.RemoveAt(currentSelectIndex); } </span><span style="color: #0000ff;"&gt;catch</span><span style="color: #000000;"&gt; (Exception ex) { Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(ex.Message); } } </span><span style="color: #0000ff;"&gt;return</span><span style="color: #000000;"&gt;; } } } }</span></pre>

3.

item = smDataContext.Suppliers.SingleOrDefault(c => c.ID == ( (item != Box.Show(删除成功!Box.Show(删除时发生错误错误信息:+

 

 

二。插入

1.

(StockManageDataContext smDataContext = User { UserName = usrName.Text,Password = pwd,Permission =Box.Show(添加用户改成功!= Box1.IsEnabled = Box2.IsEnabled = = = = Box1.Password = Box2.Password = =

2.

= 添加成功!= SolidColorBrush(Color.FromRgb(,,

三  编辑

1.

确保 编辑的对象是所选对象,所以传入参数要注意,并且编辑时要先填充控件。

 

wjkc.ExecuteCommand(</span><span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;update SHDZ set DETAIL={0},DZ={1},ISTY={2} where CODE={3};</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;,address.ISTY,address.CODE); lblMsg.Content </span>= <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;信息<a href="https://www.jb51.cc/tag/xiugai/" target="_blank" class="keywords">修改</a>成功!</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;; lblMsg.Foreground </span>= <span style="color: #0000ff;"&gt;new</span> SolidColorBrush(Color.FromRgb(<span style="color: #800080;"&gt;0</span>,<span style="color: #800080;"&gt;255</span><span style="color: #000000;"&gt;)); </span><span style="color: #008000;"&gt;//</span><span style="color: #008000;"&gt; this.Window_Closed();</span> <span style="color: #0000ff;"&gt;this</span><span style="color: #000000;"&gt;.Close(); } </span><span style="color: #0000ff;"&gt;catch</span><span style="color: #000000;"&gt; (Exception ex) { Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(ex.Message); }</span></pre>

2,。

(StockManageDataContext smDataContext = usrname = (.Parent s = smDataContext.Users.Single(c => c.UserName ===Box.Show(添加成功!.NavigationService.Navigate( Uri(Box.Show(ex.Message); label_warning.Content = 提示:密码修改失败!

 四,根据Index的值  来判断要编辑item还是要新增item。

此步是获得index,前提是父窗口或者子窗口已经传入一个带参。

Index { ; SupplierAM(= (Index > = 修改供应商信息= item = smDataContext.Suppliers.SingleOrDefault(c => c.ID ==Box_name.Text =Box_contacter.Text =Box_tel.Text =Box_fax.Text == 添加供应商信息

此步是提交按钮的事件。

button_submit_Click(= (Index > item = smDataContext.Suppliers.SingleOrDefault(c => c.ID ===Box_name.Text; item.PsContacter =Box_contacter.Text; item.PsTel =Box_tel.Text; item.PsFax =Box_fax.Text; } = =Box_name.Text; item.PsContacter =Box_contacter.Text; item.PsTel =Box_tel.Text; item.PsFax =Box_fax.Text; smDataContext.Suppliers.InsertOnSubmit(item); } Box.Show(= Box.Show(错误!错误信息: +

 

原文链接:https://www.f2er.com/csharp/238765.html

猜你在找的C#相关文章