我有一个我们正在维护的遗留VB应用程序.我们采取的设计决策是将某些数据点存储为连接字符串.由于大多数代码都是完整的,因此这一变化是一成不变的.
我正在通过一系列值运行循环.我正在做的是,查找参考表中每个值的LABEL.我需要能够在一个标签中显示值.我很难将值集中到字符串中,然后将其显示在标签中.这是我的代码......
If strField = "Expenditures" Then If InStr(1, strOldValue, ",") > 0 Then strArray = Split((strOldValue), ",") For x = 0 To UBound(strArray) For Each item In strArray strMessage = DLookUp(1, "Label", "tblText_References", "ID = '" & item & "' **''''******here I'm trying to save teh value in strMessage, however, at next item, I need it to be added to strMessage in some fashion, with a (,), I'm not sure how to do it. There are anywhere from 2 to 4 ITEMS i might have.** Next item Next End if End if
Max Vernon.. 9
你应该重新考虑如何存储膳食数据.切勿在逗号连接的单个列中存储多个值.相反,您希望创建一个表来包含所选项,然后可以JOINed
使用一对多关系将其包含到其他表中.
以下代码显示了如何完成此操作的示例.
创建一个表包含Users
谁都会有Meals
与之相关联的:
CREATE TABLE dbo.Users ( UserID INT NOT NULL CONSTRAINT PK_Users PRIMARY KEY CLUSTERED , UserName VARCHAR(255) NOT NULL );
创建一个表来描述Meals
:
CREATE TABLE dbo.Meals ( MealID INT NOT NULL CONSTRAINT PK_Meals PRIMARY KEY CLUSTERED , MealName VARCHAR(255) NOT NULL );
创建一个连接Users
到它们的联结表Meals
:
CREATE TABLE dbo.UserMeals ( UserID INT NOT NULL , MealID INT NOT NULL , CONSTRAINT PK_UserMeals PRIMARY KEY CLUSTERED (UserID, MealID) );
插入示例用户:
INSERT INTO dbo.Users (UserID, UserName) VALUES (1, 'Test User');
插入4餐:
INSERT INTO dbo.Meals (MealID, MealName) VALUES (80, 'Breakfast') , (81, 'Lunch') , (82, 'Dinner') , (83, 'Snack');
将一些示例行插入到UserMeals
与用户关联的表格中:
INSERT INTO dbo.UserMeals (UserID, MealID) VALUES (1, 80) , (1, 81);
向用户显示相关的膳食:
SELECT u.UserName , m.MealName FROM dbo.UserMeals um INNER JOIN dbo.Users u ON um.UserID = u.UserID INNER JOIN dbo.Meals m ON um.MealID = m.MealID;
结果:
你应该重新考虑如何存储膳食数据.切勿在逗号连接的单个列中存储多个值.相反,您希望创建一个表来包含所选项,然后可以JOINed
使用一对多关系将其包含到其他表中.
以下代码显示了如何完成此操作的示例.
创建一个表包含Users
谁都会有Meals
与之相关联的:
CREATE TABLE dbo.Users ( UserID INT NOT NULL CONSTRAINT PK_Users PRIMARY KEY CLUSTERED , UserName VARCHAR(255) NOT NULL );
创建一个表来描述Meals
:
CREATE TABLE dbo.Meals ( MealID INT NOT NULL CONSTRAINT PK_Meals PRIMARY KEY CLUSTERED , MealName VARCHAR(255) NOT NULL );
创建一个连接Users
到它们的联结表Meals
:
CREATE TABLE dbo.UserMeals ( UserID INT NOT NULL , MealID INT NOT NULL , CONSTRAINT PK_UserMeals PRIMARY KEY CLUSTERED (UserID, MealID) );
插入示例用户:
INSERT INTO dbo.Users (UserID, UserName) VALUES (1, 'Test User');
插入4餐:
INSERT INTO dbo.Meals (MealID, MealName) VALUES (80, 'Breakfast') , (81, 'Lunch') , (82, 'Dinner') , (83, 'Snack');
将一些示例行插入到UserMeals
与用户关联的表格中:
INSERT INTO dbo.UserMeals (UserID, MealID) VALUES (1, 80) , (1, 81);
向用户显示相关的膳食:
SELECT u.UserName , m.MealName FROM dbo.UserMeals um INNER JOIN dbo.Users u ON um.UserID = u.UserID INNER JOIN dbo.Meals m ON um.MealID = m.MealID;
结果: