TextBox从数据库返回错误的值 [英] TextBox return wrong value from database

查看:49
本文介绍了TextBox从数据库返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql中有简单的程序:

I have simple procedure in sql:

ALTER PROCEDURE AB.TicketPrice    @name varchar(50)ASBEGIN    SELECT VALUE     FROM AB.Price     WHERE Name = @name;END;






我将它用作TableAdapter,我想要负载价格值。



我有一个名为ticket的TextBox:"Nomal Ticket"。在DB中是相同的。



我有一个空的TextBox,我想用这个代码加载价格:





I use it as TableAdapter and I want load price value.

I have a TextBox with name of ticket: "Nomal Ticket". In DB is the same.

And I have an empty TextBox where I want load price with this code:

{    CinemaDataSetTableAdapters.PriceTicketTableAdapter tmp = new CinemaDataSetTableAdapters.PriceTicketTableAdapter();    int price;    string priceS;    price = tmp.Fill(cinemaDataSet.PriceTicket, NormalTextBox.Text);    priceS = price.ToString();    TESTtextBox.Text = priceS;    MessageBox.Show(priceS);  // I check value}






请帮助我女士们先生们:)



Please help me ladies and gentlemen :)

推荐答案

您好,

我创建了一个表,用模拟数据填充它。注意在不匹配我没有清除文本框,你简单做textBox1.Text ="";

I created a table, populated it with mocked data. Note in the no match I did not clear the text box, you simple do textBox1.Text = "";

创建存储过程

SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE PROCEDURE dbo.uspTicketPrice ( @name AS NVARCHAR(MAX) )
AS
    BEGIN
        SELECT  [Value]
        FROM    [ForumExamples].[dbo].[Price]
        WHERE   [Name] = @name;
    END;

GO

使用表和存储过程在项目中创建类

Created the class in the project with both the table and stored procedure

将存储过程对象拖到表单中,添加了一个文本框,运行时视图

Dragged the stored procedure object to the form, added a text box, run time view

没有匹配

表格代码

using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void fillToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                uspTicketPriceTableAdapter.Fill(forumExamplesDataSet.uspTicketPrice, nameToolStripTextBox.Text);


                if (forumExamplesDataSet.uspTicketPrice.Rows.Count > 0)
                {
                    textBox1.Text = forumExamplesDataSet
                        .uspTicketPrice.FirstOrDefault()
                        .Field<decimal>("value")
                        .ToString("C2");
                }
                else
                {
                    MessageBox.Show("No match");
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}


这篇关于TextBox从数据库返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆