При использовании регулярного выражения есть ли способ сделать его более точным?
Проблема, с которой я сталкиваюсь, заключается в том, что при попытке импортировать текст в форматированном стиле что-то попадает в назначенные места. Однако это, по-видимому, происходит при импорте больших текстовых данных. Если я вырезаю и вставляю каждый блок данных по отдельности, код, кажется, работает.
Вот пример информации и формата, которые я использую:
Page: a-01-1 & a-01-2 Number: 34 Deceased_name: Wm Aaron Race: W Sex: M Age: 34 Marital_status: Place_of_birth: DuBois Occupation: Date_of_death: Feb 28, 1895 Place_of_death: DuBois Cause_of_death: Erysiplas Duration_of_illness: 2 wks Cemetery: Karthaus cemetery Date_of_burial: Mar 4, 1895 Fathers_name: Mothers_name: Record_date: June 4, 1895 Page: a-05-1 & a-05-2 Number: 10 Deceased_name: Mary Abdenhof Race: W Sex: F Age: 1 mo Marital_status: Place_of_birth: Irvona Bor Occupation: Date_of_death: 14-Apr-03 Place_of_death: Borough Cause_of_death: Pneumonia Duration_of_illness: 1 wk Cemetery: Hagertys X Road Date_of_burial: 16-Apr-03 Fathers_name: Edward H Abdenhof Mothers_name: Catharine Abdenhof Record_date: 13-May-03
вот код, который я использую:
Dim sqlconn As New SqlConnection("constring") Dim sqladaptor = New SqlDataAdapter("select * from" + "[" + Form1.TreeView1.SelectedNode.Text.ToString + "]", sqlconn) sqlconn.Open() Dim ds As New DataSet sqladaptor.Fill(ds, Form1.TreeView1.SelectedNode.Text.ToString) Dim dt As DataTable = ds.Tables(Form1.TreeView1.SelectedNode.Text.ToString) sqlconn.Close() Dim rows() As String = Regex.Split(RichTextBox1.Text, "^\r?$", RegexOptions.Multiline) Dim pattern As New Regex("^\s*(?<label>[^:]+)\s*:\s*(?<value>.+)\s*\r?$", RegexOptions.Multiline) Dim ID As String = Nothing, Yearofbirth As String = Nothing, Firstname As String = Nothing, Lastname As String = Nothing, Middlename As String = Nothing, Placeofbirth As String = Nothing, Stateofbirth As String = Nothing, Race As String = Nothing, Residence As String = Nothing, Mothersname As String = Nothing, Mothersfirst As String = Nothing, Mothersmaiden As String = Nothing, Mothersbirthplace As String = Nothing, Maritalstatus As String = Nothing, Spouse As String = Nothing, Profession As String = Nothing, Yearofdeath As String = Nothing, SSN As String = Nothing, Placeofdeath As String = Nothing, Stateofdeath As String = Nothing, Mannerofdeath As String = Nothing, Funeralhome As String = Nothing, Placeofburial As String = Nothing, Stateofburial As String = Nothing, Inquest As String = Nothing, Inquestday As String = Nothing, Inquestmonth As String = Nothing, Inquestyear As String = Nothing, Microfilm_fileNumber As String = Nothing, Recordmonth As String = Nothing, Recordday As String = Nothing, Recordyear As String = Nothing, Statedeathcertificate As String = Nothing, Countydeathcertificate As String = Nothing, Statebirthcertificate As String = Nothing, Countybirthcertificate As String = Nothing, age As String = Nothing, Fathersname As String = Nothing, Fathersfirst As String = Nothing, Fatherslast As String = Nothing, Fathersbirthplace As String = Nothing, Sex As String = Nothing, Parents As String = Nothing, Burialorcremation As String = Nothing, Cemetery As String = Nothing, Causeofdeath As String = Nothing, Autopsy As String = Nothing, Funeralhomeaddress As String = Nothing, Claimed As String = Nothing, Unclaimed As String = Nothing, Hospital As String = Nothing, Instituteifgiven As String = Nothing, Instituteaddress As String = Nothing, Countyofdeath As String = Nothing, burial_date As String = Nothing, Monthofburial As String = Nothing, Dayofburial As String = Nothing, Year_of_burial As String = Nothing, month_of_death As String = Nothing, day_of_death As String = Nothing, Suffix As String = Nothing, Record_date As String = Nothing, Date_of_death As String = Nothing, Deceased_name As String = Nothing, Occupation As String = Nothing, Duration_of_illness As String = Nothing, Number As String = Nothing, Page As String = Nothing For Each row As String In rows Dim matches As MatchCollection = pattern.Matches(row) For Each match As Match In matches Dim label As String = match.Groups("label").Value ' For Each column In ds.Tables(Form1.TreeView1.SelectedNode.Text.ToString).Columns 'do a for each statement based on either dataset from sql statement or from checkedlistbox items If String.Equals(label, "ID", StringComparison.OrdinalIgnoreCase) Then ID = match.Groups("value").Value ElseIf String.Equals(label, "First_name", StringComparison.OrdinalIgnoreCase) Then Firstname = match.Groups("value").Value ElseIf String.Equals(label, "Last_name", StringComparison.OrdinalIgnoreCase) Then Lastname = match.Groups("value").Value ElseIf String.Equals(label, "Middle_name", StringComparison.OrdinalIgnoreCase) Then Middlename = match.Groups("value").Value ElseIf String.Equals(label, "Year_of_birth", StringComparison.OrdinalIgnoreCase) Then Yearofbirth = match.Groups("value").Value ElseIf String.Equals(label, "Place_of_birth", StringComparison.OrdinalIgnoreCase) Then Placeofbirth = match.Groups("value").Value ElseIf String.Equals(label, "State_of_birth", StringComparison.OrdinalIgnoreCase) Then Stateofbirth = match.Groups("value").Value ElseIf String.Equals(label, "Race", StringComparison.OrdinalIgnoreCase) Then Race = match.Groups("value").Value ElseIf String.Equals(label, "Residence", StringComparison.OrdinalIgnoreCase) Then Residence = match.Groups("value").Value ElseIf String.Equals(label, "Mothers_Name", StringComparison.OrdinalIgnoreCase) Then Mothersname = match.Groups("value").Value ElseIf String.Equals(label, "Mothers_first", StringComparison.OrdinalIgnoreCase) Then Mothersfirst = match.Groups("value").Value ElseIf String.Equals(label, "Mothers_maiden", StringComparison.OrdinalIgnoreCase) Then Mothersmaiden = match.Groups("value").Value ElseIf String.Equals(label, "Mothers_birth_place", StringComparison.OrdinalIgnoreCase) Then Mothersbirthplace = match.Groups("value").Value ElseIf String.Equals(label, "Marital_status", StringComparison.OrdinalIgnoreCase) Then Maritalstatus = match.Groups("value").Value ElseIf String.Equals(label, "Spouse", StringComparison.OrdinalIgnoreCase) Then Spouse = match.Groups("value").Value ElseIf String.Equals(label, "Profession", StringComparison.OrdinalIgnoreCase) Then Profession = match.Groups("value").Value ElseIf String.Equals(label, "Year_of_death", StringComparison.OrdinalIgnoreCase) Then Yearofdeath = match.Groups("value").Value ElseIf String.Equals(label, "SSN", StringComparison.OrdinalIgnoreCase) Then SSN = match.Groups("value").Value ElseIf String.Equals(label, "Place_of_death", StringComparison.OrdinalIgnoreCase) Then Placeofdeath = match.Groups("value").Value ElseIf String.Equals(label, "State_of_death", StringComparison.OrdinalIgnoreCase) Then Stateofdeath = match.Groups("value").Value ElseIf String.Equals(label, "Manner_of_death", StringComparison.OrdinalIgnoreCase) Then Mannerofdeath = match.Groups("value").Value ElseIf String.Equals(label, "Funeral_home", StringComparison.OrdinalIgnoreCase) Then Funeralhome = match.Groups("value").Value ElseIf String.Equals(label, "Place_of_burial", StringComparison.OrdinalIgnoreCase) Then Placeofburial = match.Groups("value").Value ElseIf String.Equals(label, "State_of_burial", StringComparison.OrdinalIgnoreCase) Then Stateofburial = match.Groups("value").Value ElseIf String.Equals(label, "Inquest", StringComparison.OrdinalIgnoreCase) Then Inquest = match.Groups("value").Value ElseIf String.Equals(label, "Inquest_day", StringComparison.OrdinalIgnoreCase) Then Inquestday = match.Groups("value").Value ElseIf String.Equals(label, "Inquest_month", StringComparison.OrdinalIgnoreCase) Then Inquestmonth = match.Groups("value").Value ElseIf String.Equals(label, "Inquest_year", StringComparison.OrdinalIgnoreCase) Then Inquestyear = match.Groups("value").Value ElseIf String.Equals(label, "Microfilm_file_Number", StringComparison.OrdinalIgnoreCase) Then Microfilm_fileNumber = match.Groups("value").Value ElseIf String.Equals(label, "Record_month", StringComparison.OrdinalIgnoreCase) Then Recordmonth = match.Groups("value").Value ElseIf String.Equals(label, "Record_day", StringComparison.OrdinalIgnoreCase) Then Recordday = match.Groups("value").Value ElseIf String.Equals(label, "Record_year", StringComparison.OrdinalIgnoreCase) Then Recordyear = match.Groups("value").Value ElseIf String.Equals(label, "State_death_certificate", StringComparison.OrdinalIgnoreCase) Then Statedeathcertificate = match.Groups("value").Value ElseIf String.Equals(label, "County_death_certificate", StringComparison.OrdinalIgnoreCase) Then Countydeathcertificate = match.Groups("value").Value ElseIf String.Equals(label, "State_birth_certificate", StringComparison.OrdinalIgnoreCase) Then Statebirthcertificate = match.Groups("value").Value ElseIf String.Equals(label, "County_birth_certificate", StringComparison.OrdinalIgnoreCase) Then Countybirthcertificate = match.Groups("value").Value ElseIf String.Equals(label, "Age", StringComparison.OrdinalIgnoreCase) Then age = match.Groups("value").Value ElseIf String.Equals(label, "Fathers_first", StringComparison.OrdinalIgnoreCase) Then Fathersfirst = match.Groups("value").Value ElseIf String.Equals(label, "Fathers_name", StringComparison.OrdinalIgnoreCase) Then Fathersname = match.Groups("value").Value ElseIf String.Equals(label, "Fathers_last", StringComparison.OrdinalIgnoreCase) Then Fatherslast = match.Groups("value").Value ElseIf String.Equals(label, "Fathers_birth_place", StringComparison.OrdinalIgnoreCase) Then Fathersbirthplace = match.Groups("value").Value ElseIf String.Equals(label, "Sex", StringComparison.OrdinalIgnoreCase) Then Sex = match.Groups("value").Value ElseIf String.Equals(label, "Parents", StringComparison.OrdinalIgnoreCase) Then Parents = match.Groups("value").Value ElseIf String.Equals(label, "Burial_or_cremation", StringComparison.OrdinalIgnoreCase) Then Burialorcremation = match.Groups("value").Value ElseIf String.Equals(label, "Cemetery", StringComparison.OrdinalIgnoreCase) Then Cemetery = match.Groups("value").Value ElseIf String.Equals(label, "Cause_of_death", StringComparison.OrdinalIgnoreCase) Then Causeofdeath = match.Groups("value").Value ElseIf String.Equals(label, "Autopsy", StringComparison.OrdinalIgnoreCase) Then Autopsy = match.Groups("value").Value ElseIf String.Equals(label, "Funeral_home_address", StringComparison.OrdinalIgnoreCase) Then Funeralhomeaddress = match.Groups("value").Value ElseIf String.Equals(label, "Claimed", StringComparison.OrdinalIgnoreCase) Then Claimed = match.Groups("value").Value ElseIf String.Equals(label, "Unclaimed", StringComparison.OrdinalIgnoreCase) Then Unclaimed = match.Groups("value").Value ElseIf String.Equals(label, "Hospital", StringComparison.OrdinalIgnoreCase) Then Hospital = match.Groups("value").Value ElseIf String.Equals(label, "Institute_if_given", StringComparison.OrdinalIgnoreCase) Then Instituteifgiven = match.Groups("value").Value ElseIf String.Equals(label, "Institute_address", StringComparison.OrdinalIgnoreCase) Then Instituteaddress = match.Groups("value").Value ElseIf String.Equals(label, "County_of_death", StringComparison.OrdinalIgnoreCase) Then Countyofdeath = match.Groups("value").Value ElseIf String.Equals(label, "Date_of_burial", StringComparison.OrdinalIgnoreCase) Then burial_date = match.Groups("value").Value ElseIf String.Equals(label, "Month_of_burial", StringComparison.OrdinalIgnoreCase) Then Monthofburial = match.Groups("value").Value ElseIf String.Equals(label, "Day_of_burial", StringComparison.OrdinalIgnoreCase) Then Dayofburial = match.Groups("value").Value ElseIf String.Equals(label, "Year_of_burial", StringComparison.OrdinalIgnoreCase) Then Year_of_burial = match.Groups("value").Value ElseIf String.Equals(label, "Month_of_death", StringComparison.OrdinalIgnoreCase) Then month_of_death = match.Groups("value").Value ElseIf String.Equals(label, "Day_of_death", StringComparison.OrdinalIgnoreCase) Then day_of_death = match.Groups("value").Value ElseIf String.Equals(label, "Suffix", StringComparison.OrdinalIgnoreCase) Then Suffix = match.Groups("value").Value ElseIf String.Equals(label, "Record_date", StringComparison.OrdinalIgnoreCase) Then Record_date = match.Groups("value").Value ElseIf String.Equals(label, "Date_of_death", StringComparison.OrdinalIgnoreCase) Then Date_of_death = match.Groups("value").Value ElseIf String.Equals(label, "Deceased_name", StringComparison.OrdinalIgnoreCase) Then Deceased_name = match.Groups("value").Value ElseIf String.Equals(label, "Occupation", StringComparison.OrdinalIgnoreCase) Then Occupation = match.Groups("value").Value ElseIf String.Equals(label, "Duration_of_illness", StringComparison.OrdinalIgnoreCase) Then Duration_of_illness = match.Groups("value").Value ElseIf String.Equals(label, "Number", StringComparison.OrdinalIgnoreCase) Then Number = match.Groups("value").Value ElseIf String.Equals(label, "Page", StringComparison.OrdinalIgnoreCase) Then Page = match.Groups("value").Value End If Next Try Dim sqlcon As New SqlConnection(constring) sqlcon.Open() Dim cb2 As New StringBuilder("INSERT INTO ") cb2.AppendFormat("[" + Form1.TreeView1.SelectedNode.Text.ToString + "] (") Dim sbOn As New StringBuilder("") Dim sbon1 As New StringBuilder Dim andRequired As Boolean = False For Each item As DataColumn In dt.Columns If andRequired Then sbOn.Append(", ") End If Dim columnName As String = item.ColumnName sbOn.AppendFormat(columnName) andRequired = True Next cb2.Append(sbOn.ToString() + ") values(") Dim andRequired1 As Boolean = False For Each item As DataColumn In dt.Columns ' DataGridViewColumn Form1.DataGridView1.Columns If andRequired1 Then sbon1.Append(", ") End If Dim columnName As String = item.ColumnName sbon1.AppendFormat("@" + columnName) andRequired1 = True Next cb2.Append(sbon1.ToString() + ")") ' MessageBox.Show(cb2.ToString) Dim cmd As New SqlCommand(cb2.ToString, sqlcon) 'Order of items goes by the order of this string ' Make sure that all tables have the same type of information that can be entered, if not you will recieve an error. Dim I As Integer I += 1 If dt.Columns.Contains("ID") Then cmd.Parameters.AddWithValue("@Id", If(String.IsNullOrEmpty(ID), dt.Rows.Count + I, ID)) End If If dt.Columns.Contains("Age") Then cmd.Parameters.AddWithValue("@Age", If(String.IsNullOrEmpty(age), "", age)) End If If dt.Columns.Contains("Fathers_name") Then cmd.Parameters.AddWithValue("@Fathers_name", If(String.IsNullOrEmpty(Fathersname), "", Fathersname)) End If If dt.Columns.Contains("Sex") Then cmd.Parameters.AddWithValue("@Sex", If(String.IsNullOrEmpty(Sex), "", Sex)) End If If dt.Columns.Contains("Place_of_birth") Then cmd.Parameters.AddWithValue("@Place_of_birth", If(String.IsNullOrEmpty(Placeofbirth), "", Placeofbirth)) End If If dt.Columns.Contains("Race") Then cmd.Parameters.AddWithValue("@Race", If(String.IsNullOrEmpty(Race), "", Race)) End If If dt.Columns.Contains("Marital_status") Then cmd.Parameters.AddWithValue("@Marital_status", If(String.IsNullOrEmpty(Maritalstatus), "", Maritalstatus)) End If If dt.Columns.Contains("Record_date") Then cmd.Parameters.AddWithValue("@Record_date", If(String.IsNullOrEmpty(Record_date), "", Record_date)) End If If dt.Columns.Contains("Date_of_death") Then cmd.Parameters.AddWithValue("@Date_of_death", If(String.IsNullOrEmpty(Date_of_death), "", Date_of_death)) End If If dt.Columns.Contains("Deceased_name") Then cmd.Parameters.AddWithValue("@Deceased_name", If(String.IsNullOrEmpty(Deceased_name), "", Deceased_name)) End If If dt.Columns.Contains("Occupation") Then cmd.Parameters.AddWithValue("@Occupation", If(String.IsNullOrEmpty(Occupation), "", Occupation)) End If If dt.Columns.Contains("Duration_of_illness") Then cmd.Parameters.AddWithValue("@Duration_of_illness", If(String.IsNullOrEmpty(Duration_of_illness), "", Duration_of_illness)) End If If dt.Columns.Contains("Number") Then cmd.Parameters.AddWithValue("@Number", If(String.IsNullOrEmpty(Number), "", Number)) End If If dt.Columns.Contains("Page") Then cmd.Parameters.AddWithValue("@Page", If(String.IsNullOrEmpty(Page), "", Page)) End If If dt.Columns.Contains("Mothers_name") Then cmd.Parameters.AddWithValue("@Mothers_name", If(String.IsNullOrEmpty(Mothersname), "", Mothersname)) End If If dt.Columns.Contains("Cause_of_death") Then cmd.Parameters.AddWithValue("@Cause_of_death", If(String.IsNullOrEmpty(Causeofdeath), "", Causeofdeath)) End If If dt.Columns.Contains("Cemetery") Then cmd.Parameters.AddWithValue("@Cemetery", If(String.IsNullOrEmpty(Cemetery), "", Cemetery)) End If If dt.Columns.Contains("Date_of_burial") Then cmd.Parameters.AddWithValue("@Date_of_burial", If(String.IsNullOrEmpty(burial_date), "", burial_date)) End If If dt.Columns.Contains("Place_of_death") Then cmd.Parameters.AddWithValue("@Place_of_death", If(String.IsNullOrEmpty(Placeofdeath), "", Placeofdeath)) End If cmd.Parameters.AddWithValue("@Fathers_first", If(String.IsNullOrEmpty(Fathersfirst), "", Fathersfirst)) cmd.Parameters.AddWithValue("@Fathers_last", If(String.IsNullOrEmpty(Fatherslast), "", Fatherslast)) cmd.Parameters.AddWithValue("@Fathers_birth_place", If(String.IsNullOrEmpty(Fathersbirthplace), "", Fathersbirthplace)) cmd.Parameters.AddWithValue("@First_name", If(String.IsNullOrEmpty(Firstname), "", Firstname)) cmd.Parameters.AddWithValue("@Last_name", If(String.IsNullOrEmpty(Lastname), "", Lastname)) cmd.Parameters.AddWithValue("@Middle_name", If(String.IsNullOrEmpty(Middlename), "", Middlename)) cmd.Parameters.AddWithValue("@Year_of_birth", If(String.IsNullOrEmpty(Yearofbirth), "", Yearofbirth)) cmd.Parameters.AddWithValue("@State_of_birth", If(String.IsNullOrEmpty(Stateofbirth), "", Stateofbirth)) cmd.Parameters.AddWithValue("@Residence", If(String.IsNullOrEmpty(Residence), "", Residence)) cmd.Parameters.AddWithValue("@Mothers_first", If(String.IsNullOrEmpty(Mothersfirst), "", Mothersfirst)) cmd.Parameters.AddWithValue("@Mothers_maiden", If(String.IsNullOrEmpty(Mothersmaiden), "", Mothersmaiden)) cmd.Parameters.AddWithValue("@Mothers_birth_place", If(String.IsNullOrEmpty(Mothersbirthplace), "", Mothersbirthplace)) cmd.Parameters.AddWithValue("@Spouse", If(String.IsNullOrEmpty(Spouse), "", Spouse)) cmd.Parameters.AddWithValue("@Profession", If(String.IsNullOrEmpty(Profession), "", Profession)) cmd.Parameters.AddWithValue("@Year_of_death", If(String.IsNullOrEmpty(Yearofdeath), "", Yearofdeath)) cmd.Parameters.AddWithValue("@SSN", If(String.IsNullOrEmpty(SSN), "", SSN)) cmd.Parameters.AddWithValue("@State_of_death", If(String.IsNullOrEmpty(Stateofdeath), "", Stateofdeath)) cmd.Parameters.AddWithValue("@Manner_of_death", If(String.IsNullOrEmpty(Mannerofdeath), "", Mannerofdeath)) cmd.Parameters.AddWithValue("@Funeral_home", If(String.IsNullOrEmpty(Funeralhome), "", Funeralhome)) cmd.Parameters.AddWithValue("@Place_of_burial", If(String.IsNullOrEmpty(Placeofburial), "", Placeofburial)) cmd.Parameters.AddWithValue("@State_of_burial", If(String.IsNullOrEmpty(Stateofburial), "", Stateofburial)) cmd.Parameters.AddWithValue("@Inquest", If(String.IsNullOrEmpty(Inquest), "", Inquest)) cmd.Parameters.AddWithValue("@Inquest_day", If(String.IsNullOrEmpty(Inquestday), "", Inquestday)) cmd.Parameters.AddWithValue("@Inquest_month", If(String.IsNullOrEmpty(Inquestmonth), "", Inquestmonth)) cmd.Parameters.AddWithValue("@Inquest_year", If(String.IsNullOrEmpty(Inquestyear), "", Inquestyear)) cmd.Parameters.AddWithValue("@Microfilm_file_Number", If(String.IsNullOrEmpty(Microfilm_fileNumber), "", Microfilm_fileNumber)) cmd.Parameters.AddWithValue("@Record_month", If(String.IsNullOrEmpty(Recordmonth), "", Recordmonth)) cmd.Parameters.AddWithValue("@Record_day", If(String.IsNullOrEmpty(Recordday), "", Recordday)) cmd.Parameters.AddWithValue("@Record_year", If(String.IsNullOrEmpty(Recordyear), "", Recordyear)) cmd.Parameters.AddWithValue("@State_death_certificate", If(String.IsNullOrEmpty(Statedeathcertificate), "", Statedeathcertificate)) cmd.Parameters.AddWithValue("@County_death_certificate", If(String.IsNullOrEmpty(Countydeathcertificate), "", Countydeathcertificate)) cmd.Parameters.AddWithValue("@State_birth_certificate", If(String.IsNullOrEmpty(Statebirthcertificate), "", Statebirthcertificate)) cmd.Parameters.AddWithValue("@County_birth_certificate", If(String.IsNullOrEmpty(Countybirthcertificate), "", Countybirthcertificate)) cmd.Parameters.AddWithValue("@Parents", If(String.IsNullOrEmpty(Parents), "", Parents)) cmd.Parameters.AddWithValue("@Burial_or_cremation", If(String.IsNullOrEmpty(Burialorcremation), "", Burialorcremation)) cmd.Parameters.AddWithValue("@Autopsy", If(String.IsNullOrEmpty(Autopsy), "", Autopsy)) cmd.Parameters.AddWithValue("@Funeral_home_address", If(String.IsNullOrEmpty(Funeralhomeaddress), "", Funeralhomeaddress)) cmd.Parameters.AddWithValue("@Claimed", If(String.IsNullOrEmpty(Claimed), "", Claimed)) cmd.Parameters.AddWithValue("@Unclaimed", If(String.IsNullOrEmpty(Unclaimed), "", Unclaimed)) cmd.Parameters.AddWithValue("@Hospital", If(String.IsNullOrEmpty(Hospital), "", Hospital)) cmd.Parameters.AddWithValue("@Institute_if_given", If(String.IsNullOrEmpty(Instituteifgiven), "", Instituteifgiven)) cmd.Parameters.AddWithValue("@Institute_address", If(String.IsNullOrEmpty(Instituteaddress), "", Instituteaddress)) cmd.Parameters.AddWithValue("@County_of_death", If(String.IsNullOrEmpty(Countyofdeath), "", Countyofdeath)) cmd.Parameters.AddWithValue("@Month_of_burial", If(String.IsNullOrEmpty(Monthofburial), "", Monthofburial)) cmd.Parameters.AddWithValue("@Day_of_burial", If(String.IsNullOrEmpty(Dayofburial), "", Dayofburial)) cmd.Parameters.AddWithValue("@Year_of_burial", If(String.IsNullOrEmpty(Year_of_burial), "", Year_of_burial)) cmd.Parameters.AddWithValue("@Month_of_death", If(String.IsNullOrEmpty(month_of_death), "", month_of_death)) cmd.Parameters.AddWithValue("@Day_of_death", If(String.IsNullOrEmpty(day_of_death), "", day_of_death)) cmd.Parameters.AddWithValue("@Suffix", If(String.IsNullOrEmpty(Suffix), "", Suffix)) cmd.ExecuteNonQuery() ' sqlcon.Close() Catch ex As Exception MsgBox(ex.Message) End Try Next
Может ли кто-нибудь объяснить, почему код, который я использую, не импортируется должным образом?
Что я уже пробовал:
Поскольку есть ошибки отладки, я не могу понять, где я могу изменить код, чтобы сделать его более точным.
F-ES Sitecore
Учитывая, что проблема зависит от текста, который вы ей даете, и мы не знаем, какой текст вы ей даете, трудно понять, как кто-то может помочь. Даже если бы у нас был текст, маловероятно, что кто-то будет проходить через ваш массивный дамп кода, чтобы попытаться решить проблемы. Вы должны сделать некоторую отладку, чтобы попытаться изолировать проблему.
PIEBALDconsult
С чего начать? Вы определенно слишком много работаете-например, текст.Метод toString .
Существует так много способов упростить и улучшить этот код.
Но во-первых, вы хотите сказать, что у вас есть эти огромные потоки пар ключ/значение, хранящиеся в базе данных? Как они выглядят? Всегда ли ключи находятся в одном и том же порядке?
Member 11856456
да, я пытаюсь внести эти значения в базу данных. Вот информация и формат, который я использую в настоящее время.
Страница: a-01-1 & a-01-2
Номер: 34
Deceased_name: ВМ Аарон
Гонка: W
Пол: М
Возраст: 34 года
Семейное положение:
Место рождения: Дюбуа
Занятость:
Дата Смерти: 28 Февраля 1895 Года
Place_of_death: Дюбуа
Cause_of_death: Рожа
Duration_of_illness: 2 нед
Кладбище: Кладбище Картхаус
Дата Похорон: 4 Марта 1895 Года
Fathers_name:
Mothers_name:
Дата Записи: 4 Июня 1895 Года
Страница: a-05-1 & a-05-2
Количество: 10
Имя Умершего: Мэри Абденхоф
Гонка: W
Пол: F
Возраст: 1 мес.
Семейное положение:
Место Рождения: Ирвона Бор
Занятость:
Date_of_death: 14-Apr-03
Place_of_death: Боро
Причина Смерти: Пневмония
Duration_of_illness: 1 нед
Кладбище: Хагертис-Роуд
Дата Похорон: 16-Апр-03
Имя Отца: Эдвард Х. Абденхоф
Имя Матери: Катарина Абденхоф
Дата Записи: 13 Мая-03
что вы подразумеваете под ключом?
Patrice T
Воспользуйся Улучшить вопрос чтобы обновить ваш вопрос.
Чтобы каждый мог обратить внимание на эту информацию.
PIEBALDconsult
И вы пытаетесь записать результат в другую таблицу-существует ли эта таблица?
И откуда берутся данные, прежде чем их затолкают в базу данных?
Richard MacCutchan
Это около 400 строк кода, которые вы ожидаете, что кто-то будет отлаживать для вас. Вам нужно сделать больше работы, чтобы выяснить, что происходит, и четко объяснить, что идет не так и при каких обстоятельствах.
PIEBALDconsult
И большая часть кода не нужна.