如何在文本框C#中显示SQL数据库结果 [英] How Can I Get Sql Database Results Show In Textboxs C#

查看:411
本文介绍了如何在文本框C#中显示SQL数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

i需要做查询表格,当我把[ID号]放在textbox1中并点击按钮时,特定信息将显示在textbox2和[职业]中的[age]等其他文本框中在textbox3中

数据库:试试,在服务器:11.3.2.43,tablename:table1,login:try,pass:2015

我是初学者所以我需要整个代码请..提前谢谢

hello
i need to do query form where when i put the [ID number] in textbox1 and click the button a specific information will show in other textboxs like [age] in textbox2 and [occupation] in textbox3
database:try,in server:11.3.2.43,tablename:table1,login:try,pass:2015
i'm beginner so i need the whole code please..thanks in advance

推荐答案

我是初学者所以我需要整个代码

它不是那样的工作。

我们不为你工作。

如果你想让别人写你的代码,你需要支付 - 我建议你去Freelancer.com并在那里问。



亲自尝试一下,你可能会发现它并不像你想象的那么难!



如果您遇到特定问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
"i'm beginner so i need the whole code please"
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication4
{ 
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("datasource=localhost;port=3306;username= ano;password=");
        SqlCommand com;
        SqlDataReader dr;
        string s;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
                {
                    con.Open();
                   s= ("select * from table where ID = '") + text0.Text + "',con; 
                    com = new SqlCommand(s, con);
                    dr = com.ExecuteReader();
                if(dr.Read())
             {
                 com.Parameters.AddWithValue("@name", text1.Text);
                com.Parameters.AddWithValue("@age", text2.Text);
                com.Parameters.AddWithValue("@occupation", text3.Text);

              }
                else
             {
                    MessageBox.Show("NO DATA");
              }
              }
                catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                dr.Close();
                con.Close();
            }
            
        }
  }

}          





.......................................

idont有服务器连接,这就是我应该在以后应用它的地方,所以我只是寻找可行的可​​靠方式

这是我的尝试



.......................................
idont have server connection that just what im geving i'm supposed to apply it later so i'm just looking for trusted way that will work
this is my try


这篇关于如何在文本框C#中显示SQL数据库结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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