首页 \ 问答 \ 使用wpf c#在访问数据库中插入字符串,日期和备忘录值(Insert string, date and memo value in access database using wpf c#)

使用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
更新时间:2023-06-06 07:06

最满意答案

收入JTextFieldActionListener依赖于用户按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 pressing ENTER to set the income. If this doesnt happen then assignment

tax = income * 0.10;

will produce a value tax equal to 0.

Ensure that the assignment for income occurs at the start of the ItemListener

income = Integer.parseInt(jtfIncome.getText());

before the tax calculation is made.

相关问答

更多
  • 你至少有几个选择。 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 ...
  • 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=([ ...
  • 开始改变 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 ...
  • 收入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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。