 |
|
ช่วยด้วยครับบบบ โค้ดสัั้นๆแต่ Error:ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'addApp' that has parameters: id, appname, ApplicationID, ApplicationName. |
|
 |
|
|
 |
 |
|
อันนี้โค้ดเชื่อม DB ครับ ติดมาสองวันแล้ว ขอบคุณล่วงหน้าครับ
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace ProjectPTT.LogicLayer1
{
public class DatabaseUnitTest1
{
public DataTable searchEmployee(string Fname, string Lname, string Company)
{
SqlConnection conn;
SqlCommand cmd;
string cmdString = "SELECT * FROM Employee "+
"WHERE Employee.EmployFname Like @Fname AND Employee.EmployLname Like @Lname AND Employee.Company Like @Company";
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
cmd = new SqlCommand(cmdString, conn);
cmd.Parameters.AddWithValue("@Fname","%"+Fname+"%");
cmd.Parameters.AddWithValue("@Lname","%" + Lname + "%");
cmd.Parameters.AddWithValue("@Company", "%" + Company + "%");
conn.Open();
SqlDataReader myReader;
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable returnData = new DataTable();
returnData.Load(myReader);
return returnData;
}
public DataTable searchApplication(string Appname)
{
SqlConnection conn;
SqlCommand cmd;
string cmdString = "SELECT DISTINCT Employee.* "+
"FROM Employee INNER JOIN EmApp ON Employee.EmployID = EmApp.EmployID INNER JOIN Application ON EmApp.ApplicationID = Application.ApplicationID "+
"WHERE (Application.ApplicationName Like @Appname) ";
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
cmd = new SqlCommand(cmdString, conn);
cmd.Parameters.AddWithValue("@Appname", "%" + Appname + "%");
conn.Open();
SqlDataReader myReader;
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable returnData = new DataTable();
returnData.Load(myReader);
return returnData;
}
public void addApp(string appid, string appname)
{
SqlConnection conn;
SqlCommand cmd;
string cmdString = "INSERT INTO Application(ApplicationID, ApplicationName ) " +
"VALUES(@AppID, @Appname)";
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DemoConnectionString"].ConnectionString);
cmd = new SqlCommand(cmdString, conn);
cmd.Parameters.AddWithValue("@AppID", appid);
cmd.Parameters.AddWithValue("@Appname", appname);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
|
 |
 |
 |
 |
Date :
2011-03-22 10:13:25 |
By :
Chizanu |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|