C# 删除AddWithValue调用,并使用适当的Add(名称、类型).Value方法设置参数。尤其是在使用dates@SteveFord谢谢您的建议,我将看一看服务器存储过程。希望我们部门拥有创建这些过程所需的权限。否则,在找到可能的解决方案之前,我将尝试使
C# 删除AddWithValue调用,并使用适当的Add(名称、类型).Value方法设置参数。尤其是在使用dates@SteveFord谢谢您的建议,我将看一看服务器存储过程。希望我们部门拥有创建这些过程所需的权限。否则,在找到可能的解决方案之前,我将尝试使,c#,sql-server,C#,Sql Server,删除AddWithValue调用,并使用适当的Add(名称、类型).Value方法设置参数。尤其是在使用dates@SteveFord谢谢您的建议,我将看一看服务器存储过程。希望我们部门拥有创建这些过程所需的权限。否则,在找到可能的解决方案之前,我将尝试使用正确的类:。在使用ODBC连接时,sql命令中的@参数似乎必须替换为?。我会尽快尝试并分享结果。 DECLARE @from_time Date; DECLARE @to_time Date; CREATE TABLE #temp1
删除AddWithValue调用,并使用适当的Add(名称、类型).Value方法设置参数。尤其是在使用dates@SteveFord谢谢您的建议,我将看一看服务器存储过程。希望我们部门拥有创建这些过程所需的权限。否则,在找到可能的解决方案之前,我将尝试使用正确的类:。在使用ODBC连接时,sql命令中的
@参数
似乎必须替换为?
。我会尽快尝试并分享结果。
DECLARE @from_time Date;
DECLARE @to_time Date;
CREATE TABLE #temp1
(
person_id float,
first_name varchar(100),
othercols...
)
INSERT INTO #temp1
SELECT DISTINCT
person_id, first_name, ...
FROM
campus.v_exam_registration_context context
FULL JOIN
campus.v_exam_timetable time
ON
CAST(context.examination_date AS DATETIME) = time.timetable_date
AND
context.examination_time_from = time.time_from
AND
context.examination_time_to = time.time_to
CREATE TABLE #temp2
(
exam_event_id float,
person_id float,
othercols...
)
INSERT INTO #temp2
SELECT DISTINCT
exam_event_id, person_id, excused, excused_reason, missed, modify_date, study_id, study_name,
person_exam_id, exam_in_course_id, subject, subject_unicode, personal_exam_no, exam_points, grade_description
FROM
campus.v_person_exam exam
WHERE
exam.person_id
IN
(
SELECT
#temp1.person_id
FROM
#temp1
WHERE
#temp1.attempt_counter > 1
AND
#temp1.timetable_date > @from_time
AND
#temp1.timetable_date < @to_time
)
CREATE TABLE #temp3
(
person_id float,
first_name varchar(100),
)
INSERT INTO #temp3
SELECT
#temp2.person_id, first_name, last_name, matriculation_number, attempt_counter, timetable_date, examination_date, semester, course_number, course_name,
exam_name, exam_type, component_name, course_area, module_number, module_name, credits,
FROM
#temp2
LEFT JOIN
#temp1
ON
#temp2.person_id = #temp1.person_id
AND
#temp2.exam_event_id = #temp1.exam_event_id
WHERE
#temp1.course_name IS NOT NULL
SELECT DISTINCT T1.*
FROM
#temp3 T1
INNER JOIN
(
SELECT *
FROM
#temp3
WHERE
#temp3.attempt_counter > 1
AND
#temp3.exam_points > 4
AND
#temp3.timetable_date > @from_time
AND
#temp3.timetable_date < @from_time
) as T2
ON
T1.person_id = T2.person_id
AND
T1.exam_name = T2.exam_name
ORDER BY T1.last_name ASC, T1.course_name DESC, T1.timetable_date ASC
private void queryButton_Click(object sender, RoutedEventArgs e)
{
List<Student> temp = new List<Student>();
string pass = @pass_box.Password;
string dsn = "CampusNet";
String ConnectionString =
"DSN=" + dsn + ";" +
"UID=" + uid + ";" +
"PWD=" + pass;
OdbcConnection conn = new OdbcConnection(ConnectionString);
using (conn)
{
if (conn.State.ToString() == "Open")
{
conn.Close();
}
try
{
conn.Open();
var command = new OdbcCommand(sqlcommand, conn); \\sqlcommand is read from a textfile
command.Parameters.AddWithValue("@from_time", from_time);
command.Parameters.AddWithValue("@to_time", to_time);
command.CommandTimeout = 120;
var resultCommand = command.ExecuteNonQuery();
var query = new OdbcCommand(sqlquery, conn); \\sqlquery is read from a textfile
query.Parameters.AddWithValue("@from_time", from_time);
query.Parameters.AddWithValue("@to_time", to_time);
var resultQuery = query.ExecuteReader();
Results_Box.AppendText(resultQuery.HasRows.ToString());
while (resultQuery.Read())
{
temp.Add(new Student{
name = !result.IsDBNull(3) ? result.GetString(3) : null
});
Results_Box.AppendText("Test"); \\only for testing purposes, works if I select from existing table
}
resultQuery.Close();
results = temp;
Results_Box.Document.Blocks.Add(new Paragraph(
new Run("There are " + temp.Count().ToString() + " Hits")));
System.Windows.Forms.MessageBox.Show("Connected");
conn.Close();
}
catch (Exception E)
{
Results_Box.Document.Blocks.Add(new Paragraph(new Run("Connection failed")));
Results_Box.Document.Blocks.Add(new Paragraph(new Run(E.ToString())));
}
}
}