如何避免数据冗余。 [英] How to avoid data redundancy.

查看:225
本文介绍了如何避免数据冗余。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽量避免在同一个日期和同一时间预订两次课程。

从youtube获取此代码,但它不能用于时间。如果我更改为@name或其他时间,它将工作。请帮助



我尝试过:



 Imports System.Data.OleDb 

Public Class Form1

Dim myconnstring As String =Provider = Microsoft.Jet.OleDb.4.0; Data source =& Environment.CurrentDirectory& Carst.mdb
Dim命令As OleDbCommand
Private Sub Form1_Load(sender As Object,e As EventArgs)Handles MyBase.Load
'TODO:这行代码将数据加载到'CarstDataSet .cars的表。您可以根据需要移动或删除它。
Me.CarsTableAdapter.Fill(Me.CarstDataSet.cars)

End Sub

Private Sub Savebtn_Click(sender as Object,e As EventArgs)处理Savebtn.Click
Dim myconnection As New OleDbConnection(myconnstring)
如果Car_IdTextBox.Text =或TimeDateTimePicker.Text =那么
MsgBox(请填写时间和车辆ID)
Else



Dim theQuery As String =select * from cars where Time = @ Time
Dim mycommand As New OleDbCommand(theQuery,myconnection)
mycommand.Parameters.AddWithValue(@ Time,TimeDateTimePicker)
'mycommand.Parameters.AddWithValue(@ day,Dayd)
myconnection.Open()
Dim myReader As OleDbDataReader = mycommand.ExecuteReader()
如果myReader.HasRows那么
MsgBox(已经预订,MsgBoxStyle.Exclamation,查找其他时间)
Else

Me.Validate()
Me.CarsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CarstDataSet)
MsgBox(BOOKED)
Form1_Load (我,e)
结束如果
结束如果

结束子

解决方案

开始阅读代码并弄清楚它是做什么的,以及它是如何做到的。

在互联网上找代码很好,但是如果你不希望它完全做什么它在该应用程序中完成,您将始终需要修改它以满足您的需求。这意味着要了解它是如何工作的,而不是让别人为你做功课。



发展的概念就像这句话所暗示的那样:系统性的利用科学和技术知识来满足特定的目标或要求。 BusinessDictionary.com [ ^ ]

这与有一个不一样快速谷歌并放弃,如果我找不到完全正确的代码。

所以要么付钱给别人去做,要么自己学习如何写。


< blockquote>什么是 TimeDateTimePicker

如果是 DateTimePicker类(System.Windows.Forms) [ ^ ],使用 TimeDateTimePicker。值将值设为 DateTime 对象。



另请注意 TIME 是一个保留字因此,当用作字段或表格名称时,必须用方括号括起来(通常应避免使用):

  Dim  theQuery 作为 字符串 =   SELECT * FROM cars WHERE [Time] = @ Time 


Trying to avoid booking a lesson twice on the same date and same time.
got this code from youtube but it's not working for time. If i change to @name or something other than time it will work. please help

What I have tried:

Imports System.Data.OleDb

Public Class Form1

    Dim myconnstring As String = "Provider= Microsoft.Jet.OleDb.4.0;Data source=" & Environment.CurrentDirectory & "Carst.mdb"
    Dim command As OleDbCommand
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CarstDataSet.cars' table. You can move, or remove it, as needed.
        Me.CarsTableAdapter.Fill(Me.CarstDataSet.cars)

    End Sub

    Private Sub Savebtn_Click(sender As Object, e As EventArgs) Handles Savebtn.Click
        Dim myconnection As New OleDbConnection(myconnstring)
        If Car_IdTextBox.Text = "" Or TimeDateTimePicker.Text = "" Then
            MsgBox("Please fill in the time and Car Id")
        Else



            Dim theQuery As String = "select *from cars where Time=@Time"
            Dim mycommand As New OleDbCommand(theQuery, myconnection)
            mycommand.Parameters.AddWithValue("@Time", TimeDateTimePicker)
            'mycommand.Parameters.AddWithValue("@day", Dayd)
            myconnection.Open()
            Dim myReader As OleDbDataReader = mycommand.ExecuteReader()
            If myReader.HasRows Then
                MsgBox("Already Booked", MsgBoxStyle.Exclamation, "Find some other time")
            Else

                Me.Validate()
                Me.CarsBindingSource.EndEdit()
                Me.TableAdapterManager.UpdateAll(Me.CarstDataSet)
                MsgBox("BOOKED")
                Form1_Load(Me, e)
            End If
        End If

    End sub

解决方案

Start be reading the code and working out what it does, and how it does it.
It's fine and dandy to find code on the internet, but if you don't want it to do exactly what it did in that application, you will always need to modify it to suit your needs. And that means understanding how it works, not asking someone else to do your homework for you.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself.


What is TimeDateTimePicker?
If that is a DateTimePicker Class (System.Windows.Forms)[^], use TimeDateTimePicker.Value to get the value as DateTime object.

Note also that TIME is a reserved word and must be therefore enclosed by square brackets when used as field or table name (which should be generally avoided):

Dim theQuery As String = "SELECT * FROM cars WHERE [Time]=@Time"


这篇关于如何避免数据冗余。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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