虚拟词典项目 [英] Virtual Dictionary Project

查看:121
本文介绍了虚拟词典项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,我需要一些后续步骤和编码方面的帮助.我的项目是使用我在SQL Server中建立的数据库(两个字段名称定义),大约150个字.我在Visual Studio中的表单应用程序将具有 textbox1 (用户在其中输入单词),搜索按钮 DataGridview (其中的定义)字会出现).

我需要帮助纠正我的编码,我在使用c#的SQL连接字符串上使用了许多方法,我在语法上遇到错误.大多数方法告诉您如何以添加,编辑等方式管理复杂数据.我的项目目的非常简单,我的数据存储在SQL上,我想要的只是以一种简单的方式显示结果,这将节省我的时间执行我的工作.

信息:
数据库/初始目录;拉法
服务器:Localhost或Raffa \ Rk
表格名称:字典

埃罗斯; Sqlcmd和textbox1在当前上下文中不存在

我使用了不同的代码来建立连接并且没有错误,但是运行应用程序时的查询在textbox2/datagridview中未显示任何结果.我也遇到了错误''''与Sql数据库的连接"


我的问题如下:

-没有执行这些任务的简单代码吗?

在表中的textbox1中进行1-搜索文本输入
定义字段中的2位数数据
3-在Textbox2中显示它? (我应该使用Textbox2还是Datagridview?)

应该在"buttonclick"或事件下建立连接字符串吗?

我不想添加或编辑或简化任何内容,因为在构建应用程序之前,我将通过SQL更新所有数据.

非常感谢,


当前代码:


I would like some help with the steps to follow and coding if possible. My project is to create a small dictionary software (standalone - maybe 1 form or two max) using a database I have set up in SQL server (Two fields, name and definition) with approximately 150 words. My form application in Visual Studio will have a textbox1 (Where the user writes a word) a search button and DataGridview (where the definition to that word will show up).

I need please help rectifying my coding, I have used many approaches on SQL connection string using c# , i am facing errors in the syntax. Most of the approaches tell you how to manage complex data as Adding, editing, ect.. My project purpose is very simple, My data is stored on SQL and all I want is to display the result in a simple way that will save me time performing my work.

Info:
Database/ initial catalogue ; Raffa
Server: Localhost or Raffa\Rk
Table name : Dictionnary

Erros; Sqlcmd and textbox1 does not exist in the current context

I used different codes fors establishing a connection and bug free but the query when I run the app did not show any result in the textbox2/datagridview. I had also an error ''''connection to Sql database"


My question is as follow:

- Isn''t there any simple code to perform these tasks?

1-Search text input in textbox1 in the table
2-Fecth data in the definition field
3-Display it in the Textbox2? ( Should I use Textbox2 or Datagridview? )

Should the connection string establish under the ''''buttonclick'''' or events..?

I don''t want to add or edit or cuztomize anything, As I will have all my data updated from SQL before building the application.

Thanks alot,


Current Code:


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.Sql;
using System.Data.SqlClient;



namespace strongdic
{

    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connectionString = "Initial Catalog=main;Data Source=(local);Integrated Security=SSPI;";
            SqlConnection cn = new SqlConnection(connectionString);
            string sCommand = "SELECT definition FROM Dictionnary WHERE word ='"+ TextBox1.Text.Trim()+"'",Sqlcon;
            dataGridView1.Text = Sqlcmd.ExecuteScalar().ToString();

        }


        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}

推荐答案

您不需要将文本框与sql链接.

在设计中,当您双击搜索按钮时,它将带您进入名为CLICK EVENT的块.

在其中,您需要获取textbox1值,然后将该值通过SQL QUERY传递给sql.


要建立与SQL的连接,请遵循以下步骤
希望您添加了
使用system.Data.Sql;
使用system.Data.SqlClient;
在(.cs)文件的开头,(找到事件的位置)

内部类,
Sqlconnection Sqlcon =新的Sqlconnection("Server = XXXXX; Database = YYYY; uid = sa; password = ZZZZ");

X,Y,Z是各自的SQL配置.
用于检查连接是否正常.只需双击具有文本框的设计表单,它将带您进入PAGE_LOAD事件.
在该类型中输入

Sqlcon.open();
Sqlcon.close();


如果连接正确,则在您检查运行解决方案时将不会引发任何错误.


要从SQL搜索单词

* SEARCH内部按钮点击事件

输入以下内容

Sqlcommand Sqlcmd =新的Sqlcommand(从TABLE_NAME中选择FIELDNAME,其中SEARCHFIELD =""+ textbox1.Text.Trim()+"",Sqlcon);

textbox2.Text = Sqlcmd.ExecuteScalar().ToString();



就是这样,
只需运行代码,告诉我是否发现任何错误:-)
快乐编码:-)
如果您在阅读我的语言方面遇到困难,请向我道歉;-)
You don''t need to link the textboxes with sql.

In design, While you double clicking the search button, it will send you to an block named CLICK EVENT.

Inside that you need to get your textbox1 value and pass that value to sql through SQL QUERY.


To establish Connection with SQL follow the steps
Hope you added
using system.Data.Sql;
using system.Data.SqlClient;
At the beginning of the (.cs) file,(Where the EVENTS found)

Inside Class,
Sqlconnection Sqlcon = new Sqlconnection("Server=XXXXX;Database=YYYY;uid=sa;password=ZZZZ");

Here X, Y, Z are the respective SQL config.
for checking whether the connection is working or not. Just double click on design form which you have textboxes, it will move you to an PAGE_LOAD event.
Inside that just type,

Sqlcon.open();
Sqlcon.close();


if the connection is proper, then it will not throw any errors while you check run the solutions.


To search an Word from SQL

* Inside BUTTON CLICK EVENT of SEARCH

type the following

Sqlcommand Sqlcmd = new Sqlcommand("select FIELDNAME from TABLE_NAME where SEARCHFIELD = ''"+ textbox1.Text.Trim() +"''",Sqlcon);

textbox2.Text = Sqlcmd.ExecuteScalar().ToString();



Thats all,
Just run the code and tell me if you found any errors :-)
HAPPY CODING :-)
Apology me if you found struggle in reading my LANGUAGE ;-)


这篇关于虚拟词典项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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