질문이 있습니다. 스택 및 기타 사이트에서이 질문을 연구했지만 그 답을 찾지 못했습니다. 기존 열 이름에 문자열을 첨부하는 삽입 명령을 갖고 싶습니다. 다른 달에 대해 여러 번 동일한 열을 가진 테이블이 있습니다. 열의 예 : 이름 1은 1 월이고 이름 2은 2 월이됩니다. 주소 1은 1 월이고 주소 2은 2 월 등입니다. 유일한 방법은 가로 질러 데이터에 변수를 전달하는 방법입니다, 나는 기존의 열 이름에 변수를 추가해야하므로 여러 개의 삽입 명령이 없을 것입니다. 여기 내 코드가있다.삽입 명령에서 기존 열 이름에 변수를 추가하십시오.
If MonthDDL.SelectedValue <> "" Then
Select Case MonthDDL.SelectedValue
Case Is = "January"
Month = "0"
monthVar = "January"
Case Is = "February"
Month = "1"
monthVar = "February"
Case Is = "March"
Month = "2"
monthVar = "March"
Case Is = "April"
Month = "3"
monthVar = "April"
Case Is = "May"
Month = "4"
monthVar = "May"
Case Is = "June"
Month = "5"
monthVar = "June"
Case Is = "July"
Month = "6"
monthVar = "July"
Case Is = "August"
Month = "7"
monthVar = "August"
Case Is = "September"
Month = "8"
monthVar = "September"
Case Is = "October"
Month = "9"
monthVar = "October"
Case Is = "November"
Month = "10"
monthVar = "November"
Case Is = "December"
Month = "11"
monthVar = "December"
'Case Else
End Select
selDate = MonthDDL.SelectedValue
Else
lblSelect.Visible = True
End If
DBCONN.Open()
Dim SqlUpdate = New SqlCommand("SELECT * FROM table WHERE variable = '" + Session("sessionvariable") + "'", DBCONN)
MonthDDL.SelectedValue = monthVar And dr.HasRows = True Then
SqlUpdateCommd = New SqlCommand("UPDATE table SET [table].[name] '"+ Month +'" = '" & contact & "',[table].[address]'"+ Month +'" = '" + address + "' WHERE variable = '" & Session("sessionvariable") & "'", DBCONN)
ElseIf MonthDDL.SelectedValue = monthVar And dr.HasRows = False Then
SqlUpdateCommd = New SqlCommand("INSERT INTO table (name '"+ Month +'", address '"+ Month +'", variable) Values ('" + contact + "', '" + address + "', Session("sessionvariable") + "')", DBCONN)
이 가능합니다. 나는 이것에 대해 올바른 방향으로 나아가기도합니다. 나는 vb.net을 처음 접하는 어구에 대해 사과합니다. 심지어 무엇을 검색해야할지 정말로 확신하지 못하는 이유는 무엇입니까? 미리 감사드립니다.
코드가 작동하지 않습니까? – DWright
또한 테이블 디자인을 개선하여 자신이 훨씬 편하게 만들 수 있다고 생각합니다. 나는. 다른 열 이름을 사용하는 대신 테이블을 [월], [이름], [주소]로 설정하지 않으시겠습니까? 그런 다음 행당 여러 개의 이름/주소 열을 가질 필요가 없습니다. – DWright
나는 그것이 작동 할 것이라고 생각하지 않는다. 나는 12 개월간의 데이터를 유지해야하고 데이터는 다른 문제가있는 다른 달의 문제가있는 달에서 달까지 다를 수있다. – squinny