Please i want to embid from job table. From the code below it only displays the id and pid, but what i want is to select the id, pid, embid so that i can use the embid in the next query.
Please note that the id of the embom table that has the embid is the embid in he job table i.e. id.embom = embid.job
My code
<asp:TextBox id="txtSearch1" class="autosuggest1" runat="server" Width="99%"></asp:TextBox>
<asp:TextBox id="TextBox70" class="autosuggest31" runat="server" Width="99%"></asp:TextBox>
$(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData",
data: "{ 'pid': '" + request.term + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1}]);
}
},
error: function (result) {
alert("Error");
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('[id*=hfPId]').val(ui.item.val);
}
});
}
$(function () {
SearchText31();
});
function SearchText31() {
$(".autosuggest31").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData31",
data: "{ 'embid': '" + request.term + "', id: '" + $(".autosuggest").val() + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1}]);
}
},
error: function (result) {
alert(result.responseText);
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
}
});
}
please help
[WebMethod]
public static List<string> GetAutoCompleteData(string pid)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,pid from job where pid LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", pid);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["pid"], dr["id"]));
}
return result;
}
}
}
[WebMethod]
public static List<string> GetAutoCompleteData31(string embid, string id)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,embid from job_emboss where id=@embid ", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText31", embid);
cmd.Parameters.AddWithValue("@id", embid);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["embid"], dr["id"]));
}
return result;
}
}
}
My Error
{"Message":"Conversion failed when converting the nvarchar value \u0027Test33\u0027 to data type int.","StackTrace":" at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean\u0026 dataReady)\r\n at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean\u0026 moreRows)\r\n at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean\u0026 more)\r\n at System.Data.SqlClient.SqlDataReader.Read()\r\n at Order.GetAutoCompleteData31(String embid, String id) in c:\\Users\\hp\\Documents\\Visual Studio 2010\\WebSites\\WebSite6\\Order.aspx.cs:line 173","ExceptionType":"System.Data.SqlClient.SqlException"}