我有「尋找過程或函數‘Cup_INSFuneralHome與解析和使用C#加載文本文件導入數據庫和存儲過程
一個持續的錯誤問題’需要參數‘@funeralhomename’,但未提供「。
我做了許多改動,但沒有任何效果,所以我必須從我看錯了地方。
當我調試時,它好像按正確的順序提取正確的信息。
公司名稱
地址
市州郵編
電話
我敢卡在此:作爲原始文本文件被格式化。我瀏覽了其他帖子,但一直未能找到我需要的東西,或者能夠從大量'有點'類似的帖子中提取我需要的東西。恐怕問題就在我面前,但我看不到它。我需要一雙新的眼睛。所以我提前道歉。
PROC代碼:
ALTER procedure [dbo].[Cup_INSFuneralHome]
@funeralhomename nvarchar(50),
@addressone nvarchar(50),
@addresstwo nvarchar(50),
@CityName nvarchar(50),
@State nvarchar(10),
@Zipcode nchar(10),
@Telephone nchar(15),
@PrimaryContact nvarchar (50),
@EmailAddress nvarchar (50)
as
declare @cityid uniqueidentifier
declare @stateid uniqueidentifier
select @cityid = (select cityid from [city] where CityName=(@CityName))
select @stateid = (select stateid from [State] where StateCode=ltrim(rtrim(@State)))
insert funeralhome(funeralhomename, addressone, addresstwo, cityid, stateid, zipcode, telephone, PrimaryContact, EmailAddress)
values (@funeralhomename, @addressone, @addresstwo, @CityName, @State, @ZipCode, @Telephone, @PrimaryContact, @EmailAddress)
C#代碼:
namespace abc
{
class Program
{
static void Main(string[] args)
{
address myclass = new address();
string dbConnection = "xyz";
string path = "D:\\docs\\someDocument.txt";
StreamReader sr = new StreamReader(path);
int intcount=0;
string sLine = "";
ArrayList fhome = new ArrayList();
ArrayList Ads = new ArrayList();
while (sLine != null)
{
sLine = sr.ReadLine();
if (sLine != null)
fhome.Add(sLine);
intcount=intcount+1;
}
sr.Close();
int startcount=0;
for (int n = 0; n < fhome.Count; n++)
{
char[] delim = {',', ' '};
try
{
if (startcount == 0)
{
myclass = new address();
}
if (fhome[n].ToString().Trim().Length > 0)
{
if (!fhome[n].ToString().Contains("Funeral Home Profile"))
{
switch (startcount)
{
case 0:
myclass.company = fhome[n].ToString().Trim();
startcount = startcount + 1;
break;
case 1:
myclass.address1 = fhome[n].ToString().Trim();
startcount = startcount + 1;
break;
case 2:
myclass.address2 = fhome[n].ToString().Trim();
startcount = startcount + 1;
break;
case 3:
myclass.telephone = fhome[n].ToString().Trim();
startcount = 0;
Ads.Add(myclass);
break;
}
}
}
}
catch { }
}
SqlConnection conn = new SqlConnection(dbConnection);
for(int n=0;n< Ads.Count;n++)
{
address tclass = (address)Ads[n];
int comloc;
comloc = tclass.address2.IndexOf(",");
string funeralhomename = tclass.company.ToString();
string street = tclass.address1.ToString();
string street2 = "";
string city = tclass.address2.Substring(0, comloc);
string state = tclass.address2.Substring(comloc + 1, 3);
string zip = tclass.address2.Substring(comloc + 4);
string tel = tclass.telephone.Replace("Local:", "");
string PrimaryContact = "";
string EmailAddress = "";
string tsql = "";
tsql = (funeralhomename + ',' +
street + ',' + street2 + city + ',' +
state + zip + tel + PrimaryContact + EmailAddress);
conn.Open();
try
{
SqlCommand cmd = new SqlCommand("Cup_INSFuneralHome", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] param = new SqlParameter[9];
param[0] = new SqlParameter("@funeralhomename", SqlDbType.NVarChar);
param[0].Value = funeralhomename;
param[1] = new SqlParameter("@addressone", SqlDbType.NVarChar);
param[1].Value = street;
param[2] = new SqlParameter("@addresstwo", SqlDbType.NVarChar);
param[2].Value = street2;
param[3] = new SqlParameter("@cityname", SqlDbType.NVarChar);
param[3].Value = city;
param[4] = new SqlParameter("@State", SqlDbType.NVarChar);
param[4].Value = state;
param[5] = new SqlParameter("@zipCode", SqlDbType.NChar);
param[5].Value = zip;
param[6] = new SqlParameter("@Telephone", SqlDbType.NChar);
param[6].Value = tel;
param[7] = new SqlParameter("@PrimaryContact", SqlDbType.NVarChar);
param[7].Value = PrimaryContact;
param[8] = new SqlParameter("@EmailAddress", SqlDbType.NVarChar);
param[8].Value = EmailAddress;
cmd.ExecuteNonQuery();
}
catch
{
Debug.Print("Error with.." + tclass.company);
}
finally
{
conn.Close();
}
Debug.Print(tsql);
}
}
}
}
public class address
{
private string _company;
private string _address1;
private string _address2;
private string _telephone;
public string company
{
get { return _company; }
set { _company = value; }
}
public string address1
{
get { return _address1; }
set { _address1 = value; }
}
public string address2
{
get { return _address2; }
set { _address2 = value; }
}
public string telephone
{
get { return _telephone; }
set { _telephone = value; }
}
}
cityid和stateid是uniqueidentifier ???你生氣嗎??你期望有多少個州和城市? – 2010-12-15 14:58:11
殯儀館基於「客戶」和/或墓地的城市和州 – 2010-12-15 16:24:47
非常感謝您,我已經實施了必要的更改,但是現在我得到'轉換失敗時,從字符串轉換爲唯一標識符'。我甚至改變了過程,並用UID去取得數據,但錯誤仍在繼續 – 2010-12-15 19:10:17