Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
This code is Getting Executed but when i type a letter in textbox it pops System.Data.DataRow


[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetName(string prefixText)
{
OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
//con.ConnectionString = ConfigurationManager.ConnectionStrings["dbconnection"].ToString();



con.Open();

string query = "select name from vpro where name like :Name||'%'";
//Console.Write("select name from vpro where name like :Name||'%'");
OracleCommand cmd = new OracleCommand(query, con)
{ CommandType = CommandType.Text };


cmd.Parameters.AddWithValue(":Name", prefixText);

OracleDataAdapter sda = new OracleDataAdapter(cmd);
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(ds);
dt = ds.Tables[0];
List<string> name = new List<string>();

for (int i = 0; i < dt.Rows.Count; i++)
{
name.Add(dt.Rows[0].ToString());
}

return name;

}
Posted
Updated 22-Mar-13 2:42am
v2
Comments
[no name] 21-Mar-13 16:38pm    
This is just an unformatted code dump. No question asked and no explanation.
[no name] 22-Mar-13 8:58am    
Yes of course it will. That is exactly what dt.Rows[0].ToString() will do. Did you try dt.Rows[0][i].ToString()?
akash02asp 22-Mar-13 9:20am    
Greattttttt !!!!! Got it.


yes can u explain me plzzz.
[no name] 22-Mar-13 9:21am    
Explain what?
akash02asp 22-Mar-13 9:22am    
Wat is happening really there
dt.Rows[0].ToString() ---> dt.Rows[0][i].ToString()

What is the error you getting ? seems to be code correct but I have one suggestion use foreach instead of for loop.
 
Share this answer
 
Comments
akash02asp 22-Mar-13 8:27am    
It is getting excuted but
When i type a letter in textbox eg:- d .
It is getting System.Data.DataRow
akash02asp 22-Mar-13 11:11am    
Thank you SivaKrishna :)
dt.Rows[0].ToString() ---> dt.Rows[0][i].ToString()


Solved.
Thank you ThePhantomUpvoter.
 
Share this answer
 
Solved Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.OracleClient;
using System.Data;

public partial class ajaxautocomplete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}


[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCountries(string prefixText)
{

OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
con.Open();

string query = "select name from vpro where name like :Name||'%'";
//Console.Write("select name from vpro where name like :Name||'%'");
OracleCommand cmd = new OracleCommand(query, con) { CommandType = CommandType.Text };
cmd.Parameters.AddWithValue(":Name", prefixText);
OracleDataAdapter sda = new OracleDataAdapter(cmd);
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(ds);
dt = ds.Tables[0];
string[] name = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
name.SetValue(dr["name"].ToString(), i);
i++;
}
return name;
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900