数据库和消息框 [英] database and message box

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

问题描述

我有两种形式:
-一个是用来搜索电影的.
-第二个是添加电影.

我想要的是如果某人添加了一个电影,例如Fast5,并且该电影已经存在于数据库中,我想显示一个错误消息框,告知该电影已经存在,而不是程序崩溃.

如果数据库中不存在电影,则搜索电影的方法也是一样.消息框提示没有这样的电影.

I have two forms:
- One is for searching the movie.
- Second one is for adding movie.

What I would like is if a person adds a movie say Fast5 and that movie already exists in the database I want to show an error message box telling that the movie already exist rather then the program crash.

Same thing for the search for a movie if it does not exist in the database an message box telling that there is no such movie.

推荐答案

所以没有适合您的代码!
但是,它并不复杂:您需要添加一个get来自数据库的电影详细信息"功能.

1)连接到数据库
2)使用字符串"SELECT * FROM myTable WHERE movieName = @ MN"设置一个SQL命令.
3)使用SQLCommand函数Parameters.AddWithValue将参数"@MN"添加到命令中,该值是影片名称.
4)使用SQLCommand函数Exec​​uteReader从数据库读取记录.
5)如果reader.Read函数返回true,则说明数据库中有一部电影带有比名字的电影-您可以检索这些字段.
6)如果没有,则没有该名称的电影.
This smells badly of homework, so no code for you!
However, it isn''t complex: you need to add a get "the movie details from the database" function.

1) Connect to the database
2) Set up a SQL command, with the string "SELECT * FROM myTable WHERE movieName=@MN"
3) Use the SQLCommand function Parameters.AddWithValue to add the parameter "@MN" to the command, with the value being the movie name.
4) Use the SQLCommand function ExecuteReader to read records from the DB.
5) If the reader.Read function returns true, there is a movie with than name in the db - you can retrieve the fields.
6) If it doesn''t, there is no movie of that name.


这篇关于数据库和消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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