Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
  <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
        google.load('visualization', '1', { packages: ['orgchart'] });
        google.setOnLoadCallback(drawVisualization);
        function drawVisualization() {
            // Create and populate the data table.
            var data = google.visualization.arrayToDataTable([
    //['Name', 'Manager', 'Tooltip'],
   // ['Mike', null, 'The President'],
  //  [{ v: 'Jim', f: 'Jim<br/><font color="red">Vice President</font>' }, 'Mike', null],
   // ['Alice', 'Mike', null],
   // ['Bob', 'Jim', 'Bob Sponge'],
   // ['Carol', 'Bob', null]
 // ]);
            var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
            chart.draw(data, { allowHtml: true });
        }
    </script>

    <script type="text/javascript">
        function Page_Load()
            {
                
        var conn = "abc";
        SqlConnection con;
        con=new SqlConnection(@conn);
        SqlCommand cmd=new SqlCommand("select Name from tblXYZ where T_Position='Manager'",con);
        DataTable ds=new DataTable();
        SqlDataAdapter da=new SqlDataAdapter();
        da.Fill(ds);
        
            }

    </script>





Here i wants to use my datatable in the above script i.e. in commented area.
first i dont know how to execute sql statement in script and then how to use element of it in script.plzz help me
thanx in advance..
Posted

Fisrt of all about how to execute SQL Statement in Java Script(Check below sample code).
javscript doesn't have direct support to execute sql query.But with the help of activ object you can accomplish the same.
C#
select

function gen_list_options(query, id, val) {

var conn = Server.CreateObject("ADODB.Connection");
var constr = "DSN=yourdsn; Uid=sa; Pwd=sa";
conn.Open (constr);
var rs = new ActiveXObject("ADODB.Recordset")
rs.open(query, conn, adOpenDynamic, adLockOptimistic)
if(!rs.bof) {
rs.MoveFirst()
while(!rs.eof) {
html += '<option value="' + rs.fields(id).value + '">' + rs.fields(val).value + '</option>'
rs.MoveNext()
}
}
rs.close()
return html
}

Updation

var con = Server.CreateObject("ADODB.Connection");
var constr = "DSN=yourdsn; Uid=sa; Pwd=sa";
con.Open (constr);
var querycompupd = "UPDATE Tasks SET Status='"&status&"' WHERE ID = " + tnum + ";";
con.execute(querycompupd);

Now Check This Link[^] to understante the enire process in details regarding how to used your database connection within the Java Script.
 
Share this answer
 
v2
Comments
Member 10202727 25-Oct-13 5:21am    
Sir thanx for it but can you make it clear as i am beginer in it i dont know how to go with it as i had just know



String conn= "Data Source=abcs";
SqlConnection con;
con=new SqlConnection(@conn);
SqlCommand cmd=new SqlCommand("select T_Name from xyz where T_Position='manager'",con);
DataSet ds=new DataSet();
DataTable dt=new DataTable();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(dt);


such type of connections...
or if you have link which will explain me then just provide me with it will go through...
bjdestiny 25-Oct-13 5:48am    
Hi,
First of all Just Create simple Javascript Function so that you could get your exact idea like below code.
function somedata(Myvalue)
{alert(Myvalue)}

and Use Simple RegisterscriptBlock
http://www.codeproject.com/KB/aspnet/scriptregister.aspx
RegisterClientScriptBlock("Script4","somedata('"+<yourdata from="" server="">+"'";","Javascript", true);
Up to this if your are going very well then i think you might have solve your problem.
Member 10202727 25-Oct-13 5:56am    
thanx a ton... :)
bjdestiny 25-Oct-13 5:59am    
Work it???
Member 10202727 25-Oct-13 6:26am    
NOT ACTUALLY BUT THE EXPLANATION U GAVE WAS UNDERSTANDABLE THATS WHY THANKS
N I AM VERY CLOSE TO MY ANSWER BUT UNABLE RETRIEVE HIERARCHY ...
I HAVE FIELD LIKE THIS

USERNAME NAME POSITION
ABC SDSD MANAGER
XYZ DSD EMPLOYEE
GHF SD MANAGER
GH DD DIRECTOR

LIKE THIS AND I WANT TO RETRIEVE HIERARCHICAL RELATION BETWEEN THEM IN THE FORM - NAME & UPPERPOST


I HAVE CODE FOR ORG CHAT SOMETHING LIKE THIS...

JavaScript
          <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="//www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load('visualization', '1', { packages: ['orgchart'] });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json',
                url: 'Default.aspx/GetData',
                data: '{}',
                success:
                    function (response) {
                        drawVisualization(response.d);
                    }

            });
        })

function drawVisualization(datavalues) {
            // Create and populate the data table.
            var data = google.visualization.DataTable();
            data.addColumn('string', 'Name');
            data.addColumn('string', 'Manager');
            data.addColumn('string', 'ToolTip');
            

            for (var i = 0; i < dataValues.length; i++) {
                data.addRow([dataValues[i].ColumnName, dataValues[i].Value]);
            }
            //['Name', 'Manager', 'Tooltip'];


            // Create and draw the visualization.
            new google.visualization.OrgChart(document.getElementById('visualization')).
      draw(data, { allowHtml: true });
        }
         
    </script>



BEHIND IT
ASPX.CS

[WebMethod]
public static List GetData()
{
SqlConnection conn = new SqlConnection(""SDSDS);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
conn.Open();
string cmdstr = "select top 5 Country, COUNT(CompanyName) [Total Suppliers] from [Suppliers] group by Country";
SqlCommand cmd = new SqlCommand(cmdstr, conn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
dt = ds.Tables[0];
List dataList = new List();
string cat="";
int val=0;
foreach (DataRow dr in dt.Rows)
{
cat=dr[0].ToString();
val=Convert.ToInt32( dr[1]);
dataList.Add(new Data(cat, val));
}
return dataList;
}
}
public class Data
{
public string ColumnName = "";
public int Value = 0;

public Data(string columnName, int value)
{
ColumnName = columnName;
Value = value;
}
}




I NEED QUERY THAT WILL PASS MY VALUE TO CODE
TAHNX IN ADVANCE
 
Share this answer
 
find this solution and it wrks for me to retrieve it into an marquee

ASP.NET
<marquee id="mar1" runat="server" direction="right" onmouseover="this.stop()">
               onmouseout="this.start()" scrollamount="2" scrolldelay="1" style="width:100%;color:Red;">


      </marquee>


in code behind


C#
public void retrivenotify()
   {
       con = new SqlConnection(@conn);
       string login1 = "select TOP 1 Name from Demo  order by Notify_Id DESC";

       SqlCommand cmd1 = new SqlCommand(login1, con);

       con.Open();
       SqlDataReader user = cmd1.ExecuteReader();
       if (user.HasRows)
       {
           user.Read();
           SqlDataReader t1;
           user.Close();
           t1 = cmd1.ExecuteReader();
           t1.Read();
           this.mar1.InnerHtml = t1[0].ToString();
           //what to do for newpoint in newline
           con.Close();
       }
   }
 
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