使用wpf c#在访问数据库中插入字符串,日期和备忘录值(Insert string, date and memo value in access database using wpf c#)
我有4个控件。 一个是参考号,日期,主题和正文。 引用号和主题是msaccess中长度为255个字符的文本字段。 正文字段是备忘录字段。 问题是当我尝试使用参数函数将值插入表中时,我在SQL命令文本中仅采用备注字段,命令功能成功执行。
但是,只要我包含任何其他字段,我就会收到错误“字段太小而无法接受您输入的数据量。请尝试插入或粘贴较少的数据。” 任何人都可以帮我解决这个错误吗?
编码如下:
if (btnNew.Content.Equals("_New")) { btnNew.Content = "_Save"; Clear_Contents(); dtpDate.Focus(); btnMod.IsEnabled = false; btnDel.IsEnabled = false; btnPrint.IsEnabled = false; } else { OleDbConnection conn = DBConnection.getDBConnection(); OleDbCommand command = conn.CreateCommand(); string rtfText; TextRange richText = new TextRange(txtBody.Document.ContentStart,txtBody.Document.ContentEnd); using (MemoryStream ms = new MemoryStream()) { richText.Save(ms, DataFormats.Rtf); rtfText = Encoding.ASCII.GetString(ms.ToArray()); } try { command.Parameters.Add("@body", OleDbType.LongVarChar).Value=rtfText; command.Parameters.Add("@refno",OleDbType.VarChar,255).Value=txtPCode.Text; command.CommandText = "insert into letter_master(total_ref,let_body)values (@refno,@body)"; conn.Open(); command.ExecuteNonQuery(); conn.Close(); MessageBox.Show("Record Saved Successfully !!!", DBConnection.Comp_Name, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
I have 4 controls. One is reference no, date, subject and body. reference no and subject are text fields in msaccess with 255 characters length. Body field is memo field. Problem is when I try to insert values into the table using parameter function and I take only memo field in my SQL commandText the command function is executed successfully.
But as soon as I include any other field I start getting error "The field is too small to accept the amount of data you entered. Try inserting or pasting less data." Can anybody help me how to solve this error?
Coding is as follows :
if (btnNew.Content.Equals("_New")) { btnNew.Content = "_Save"; Clear_Contents(); dtpDate.Focus(); btnMod.IsEnabled = false; btnDel.IsEnabled = false; btnPrint.IsEnabled = false; } else { OleDbConnection conn = DBConnection.getDBConnection(); OleDbCommand command = conn.CreateCommand(); string rtfText; TextRange richText = new TextRange(txtBody.Document.ContentStart,txtBody.Document.ContentEnd); using (MemoryStream ms = new MemoryStream()) { richText.Save(ms, DataFormats.Rtf); rtfText = Encoding.ASCII.GetString(ms.ToArray()); } try { command.Parameters.Add("@body", OleDbType.LongVarChar).Value=rtfText; command.Parameters.Add("@refno",OleDbType.VarChar,255).Value=txtPCode.Text; command.CommandText = "insert into letter_master(total_ref,let_body)values (@refno,@body)"; conn.Open(); command.ExecuteNonQuery(); conn.Close(); MessageBox.Show("Record Saved Successfully !!!", DBConnection.Comp_Name, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
原文:https://stackoverflow.com/questions/23567737
最满意答案
收入
JTextField
的ActionListener
依赖于用户按ENTER来设置income
。 如果没有发生那么分配tax = income * 0.10;
将产生等于
0
的价值tax
。确保
income
分配发生在ItemListener
的开头income = Integer.parseInt(jtfIncome.getText());
在进行税务计算之前。
The
ActionListener
for the incomeJTextField
relys on the user pressing ENTER to set theincome
. If this doesnt happen then assignmenttax = income * 0.10;
will produce a value
tax
equal to0
.Ensure that the assignment for
income
occurs at the start of theItemListener
income = Integer.parseInt(jtfIncome.getText());
before the tax calculation is made.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你至少有几个选择。 OOXml SDK 如果excel文件是2007格式(xlsx)或更高版本,则可以通过Microsoft提供的OOXml SDK以编程方式使用它。 看看以下方法: 如何:检索电子表格文档中的单元格值 对于电子表格的其他方法: http://msdn.microsoft.com/en-us/library/office/cc850837.aspx 互操作 您可以自动执行excel并以编程方式与其进行交互。 这需要在运行程序的计算机上安装excel。 Microsoft还提醒说,服务器环境不 ...
-
您可以使用Auth::user()获取当前登录的用户。 因此,如果您想在登录后在会话中存储用户的用户名,您可以这样做: $user = Auth::user(); Session::put('username', $user->username); You can get the currently logged in user with Auth::user(). So, if you wanted to store the user's username in the session after lo ...
-
创建一个IM bot(Creating an IM bot)[2022-04-12]
Google Talk使用jabber,协议称为XMPP 。 快速谷歌搜索“xmpp机器人php”带领我到这里 。 这应该足够一开始? Taken from the tutorial in case it ever disappears: Step 1: Go to imified.com and request an invite. You should also give your bot a decent name because you can have just one bot per email ... -
这种方式适用于将来有人需要它的情况。 既然它是一个动作,我不想镜像组合框本身的任何变化,我决定使用ActionListener而不是ItemListener comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e){ { serverText.setText( (Strin ...
-
我尝试使用ArrayList和ArrayList,但它不起作用,因为我设置水平对齐报告错误的行:这是预期的,因为Object / JComponent没有setHorizontalAlignment方法。 因此,您需要将其关联到JTextField并调用此API。 我不确定这是否是一个好主意,至于关闭对象,你需要知道每个索引存储的对象的实际类型是什么类型(JTextFild或JComboBox),否则你将使用ClassCasteException 。 I've found a solution to my ...
-
您可以在/.htaccess文件中使用以下内容: RewriteEngine on RewriteCond %{QUERY_STRING} aff_id=([\w]+) [NC] RewriteRule ^$ /?ap_id=%1 [R,L] 如果您想使重定向成为永久性,请将R更改为R=301 。 You can use the following in your /.htaccess file: RewriteEngine on RewriteCond %{QUERY_STRING} aff_id=([ ...
-
所得税计算器(Income tax calculator)[2022-10-24]
开始改变 TaxReturn theCalculator = new TaxReturn(income); System.out.println("The amount of tax is: " + taxReturn.getTax()); 至 TaxReturn theCalculator = new TaxReturn(income); System.out.println("The amount of tax is: " + theCalculator .getTax ... -
需要帮忙。(Need help. Im trying to create a combobox and some textfields for a class project on taxable income)[2023-05-06]
收入JTextField的ActionListener依赖于用户按ENTER来设置income 。 如果没有发生那么分配 tax = income * 0.10; 将产生等于0的价值tax 。 确保income分配发生在ItemListener的开头 income = Integer.parseInt(jtfIncome.getText()); 在进行税务计算之前。 The ActionListener for the income JTextField relys on the user pressi ...