|
|
Hi,
As i am fresher in ADO.NET so, i don't know what should be asked on Machine Round Test on interview.
Can anyone help?
Thanks...
|
|
|
|
|
Never heard of it. Did you do any searching?
|
|
|
|
|
Answering a few stock questions will not help you pass an interview. You need to fully understand the subject.
|
|
|
|
|
Hi,
How to get data from Multiple Tables and display it in single Grid view.
|
|
|
|
|
Execute a query. Or multiple.
What did you try and where are you stuck? This sounds like a very generic beginners' question, and without additional information, I'd suggest you try Googeling for examples.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
HI,
This is my code but this code is not working,that means it
not displaying data from tables in Grid view.
Default.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
String a, b;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
bindGrid();
}
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd = new SqlCommand("Select Department_ID,Department from Department_Master", con);
SqlDataReader dr = cmd.ExecuteReader();
ddldept.DataSource = dr;
ddldept.DataBind();
con.Close();
bindGrid();
}
void bindGrid()
{
SqlConnection con1 = new SqlConnection(Class1.Con_String);
con1.Open();
SqlCommand cmd1 = new SqlCommand("Select Designation_ID,Designation from Designation_Master", con1);
SqlDataReader dr1 = cmd1.ExecuteReader();
ddldesg.DataBind();
con1.Close();
SqlConnection con11 = new SqlConnection(Class1.Con_String);
con11.Open();
String cmd11 = "Select Employee_Master.Emp_ID,Employee_Master.Emp_Name,Employee_Master.Email_ID,Employee_Master.Salary,Employee_Master.Photo,Department_Master.Department,Designation_Master.Designation,Employee_Master.Department_ID,Employee_Master.Designation_ID from Employee_Master Inner Join Department_Master on Employee_Master.Department_ID=Department_Master.DEpartment_ID Inner Join Designation_Master on Employee_Master.Desgination_ID=Designation_Master.Designation_ID";
bool whereadded=false;
if(ddldept.SelectedIndex>0)
{
cmd11 += "where Department_Master.Department_ID="+ ddldept.SelectedValue;
GridView1.EditIndex = -1;
whereadded = true;
}
if (ddldesg.SelectedIndex > 0)
{
if (whereadded == true)
{
GridView1.EditIndex = -1;
cmd11 += "and Designation_Master.Designation_ID=" + ddldesg.SelectedValue;
}
}
if (ViewState["sort"] != null)
{
cmd11 += "order by"+ ViewState["sort"];
GridView1.EditIndex = -1;
}
SqlDataAdapter da = new SqlDataAdapter(cmd11,con11);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con11.Close();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["sort"] = e.SortExpression;
bindGrid();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;
GridView1.PageIndex = e.NewPageIndex;
bindGrid();
}
protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
{
bindGrid();
}
protected void ddldesg_SelectedIndexChanged(object sender, EventArgs e)
{
bindGrid();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
a=GridView1.DataKeys[e.NewEditIndex].Values[1].ToString();
b=GridView1.DataKeys[e.NewEditIndex].Values[2].ToString();
GridView1.EditIndex = e.NewEditIndex;
bindGrid();
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd1 = new SqlCommand("Select Designation_ID,Designation from Designation_Master",con);
SqlDataReader dr1 = cmd1.ExecuteReader();
DropDownList ddl2=((DropDownList)GridView1.Rows[e.NewEditIndex].Cells[6].FindControl("ddl2"));
ddl2.DataSource = dr1;
ddl2.DataBind();
ddl2.SelectedValue = b;
con.Close();
SqlConnection conn = new SqlConnection(Class1.Con_String);
conn.Open();
SqlCommand cmd2 = new SqlCommand("Select Department_ID,Department from Department_Master",conn);
SqlDataReader dr2 = cmd2.ExecuteReader();
DropDownList ddl1=((DropDownList)GridView1.Rows[e.NewEditIndex].Cells[5].FindControl("ddl1"));
ddl1.DataBind();
ddl1.SelectedValue = a;
conn.Close();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bindGrid();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal salary=(decimal)DataBinder.Eval(e.Row.DataItem,"Salary");
if ((salary > 50000) && (salary < 75000))
{
e.Row.ForeColor = Color.Red;
}
else
{
e.Row.ForeColor = Color.Green;
}
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String id = GridView1.DataKeys[e.RowIndex].Value.ToString();
String name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("txtname")).Text;
String email=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("txtemail")).Text;
String salary=((TextBox)GridView1.Rows[e.RowIndex].Cells[3].FindControl("txtsalary")).Text;
FileUpload photo=((FileUpload)GridView1.Rows[e.RowIndex].Cells[4].FindControl("fuphoto"));
String desgname=((DropDownList)GridView1.Rows[e.RowIndex].Cells[6].FindControl("ddl2")).SelectedValue;
String departname=((DropDownList)GridView1.Rows[e.RowIndex].Cells[5].FindControl("ddl1")).SelectedValue;
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
if (photo.HasFile)
{
SqlCommand cmd = new SqlCommand("Update Employee_Master Set Employee_Master.Emp_Name=@name,Employee_Master.Email_ID=@email,Employee_Master.Salary=@salary,Employee_Master.Photo=@photo,Employee_Master.Department_ID=@departname,Employee_Master.Designation_ID=@desgname where Employee_Master.Emp_ID="+id,con);
cmd.Parameters.AddWithValue("@name",name);
cmd.Parameters.AddWithValue("@email",email);
cmd.Parameters.AddWithValue("@salary",salary);
cmd.Parameters.AddWithValue("@ photo",photo);
cmd.Parameters.AddWithValue("@desgname",desgname);
cmd.Parameters.AddWithValue("@departname",departname);
}
SqlCommand cmd1 = new SqlCommand("Update Employee_Master Set Employee_Master.Emp_Name=@name,Employee_Master.Email_ID=@email,Employee_Master.Salary=@salary,Employee_Master.Department_ID=@departname,Employee_Master.Designation_ID=@desgname where Employee_Master.Emp_ID="+ id,con);
cmd1.Parameters.AddWithValue("@name",name);
cmd1.Parameters.AddWithValue("@email",email);
cmd1.Parameters.AddWithValue("@salary",salary);
cmd1.Parameters.AddWithValue("@desgname",desgname);
cmd1.Parameters.AddWithValue("@departname",departname);
cmd1.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bindGrid();
}
===========================================================================================================
Default2.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String id=Request.QueryString["Emp_ID"];
if (id == null)
{
Response.Redirect("Default.aspx");
return;
}
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd = new SqlCommand("Select Employee_Master.Emp_ID,Employee_Master.Emp_Name,Employee_Master.Email_ID,Employee_Master.Salary,Employee_Master.Photo,Employee_Master.Department_ID,Employee_master.Designation_ID, Department_Master.Department_ID,Designation_Master.Designation_ID from Employee_Master Inner Join Department_Master on Employee_Master.Department_ID=Designation_Master.Desgination_ID",con);
SqlDataReader dr = cmd.ExecuteReader();
DetailsView1.DataSource = dr;
DetailsView1.DataBind();
con.Close();
}
}
|
|
|
|
|
Those select-statements do not return the same amount of columns; how would you show them in a grid?
If they *do* have the same amount of columns, than you could use a UNION statement to combine the resultsets.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Member 11161625 wrote:
if(ddldept.SelectedIndex>0)
{
cmd11 += "where Department_Master.Department_ID="+ ddldept.SelectedValue;
GridView1.EditIndex = -1;
whereadded = true;
}
if (ddldesg.SelectedIndex > 0)
{
if (whereadded == true)
{
GridView1.EditIndex = -1;
cmd11 += "and Designation_Master.Designation_ID=" + ddldesg.SelectedValue;
}
}
if (ViewState["sort"] != null)
{
cmd11 += "order by"+ ViewState["sort"];
GridView1.EditIndex = -1;
}
This code is susceptible to SQL Injection[^]. You need to use a parameterized query, as you did in your GridView1_RowUpdating method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please try following:
1. Mention the Text field and Value field for drop down list
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd = new SqlCommand("Select Department_ID,Department from Department_Master", con);
SqlDataReader dr = cmd.ExecuteReader();
ddldept.DataSource = dr;
ddldept.DataTextField = "Department"
ddldept.DataValueField = "Department_ID";
ddldept.DataBind();
con.Close();
bindGrid();
2. You are missing specifying the datasource for Designation Master DDL. Please try following:
SqlConnection con1 = new SqlConnection(Class1.Con_String);
con1.Open();
SqlCommand cmd1 = new SqlCommand("Select Designation_ID,Designation from Designation_Master", con1);
SqlDataReader dr1 = cmd1.ExecuteReader();
ddldesg.Datasource = dr1;
ddldesg.DataTextField = "Designation"
ddldesg.DataValueField = "Designation_ID";
ddldesg.DataBind();
con1.Close();
|
|
|
|
|
Need help guys...
Can any body give me some code which can just help me capturing images from an ip-cam sing VB.NET?
|
|
|
|
|
|
Hi All,
I have came across a requirement, where converting a traditional excel application (with 7-8 diff sheets and each sheet with 50k cells and lots of macros / tables in it) into a web application.
Can any one suggest me which is the best way of doing this in .net, where I have to resemble the application just like the excel sheet. Here the challenging part is importing all the data, formulea and the macros into the web application, and have the luxury of SQL server as well for data. The JSON data of each sheet along with formulas and values is coming around 4mb.
Your suggestion are valuable and very much appreciated.
Thanks,
Sujana
|
|
|
|
|
What? You have to recreate Excel? That will take an inordinate amount of time. Perhaps use google docs or microsoft online.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Yes its almost like recreating the application. But looking for option where we can embed the excel into the application and import the data.
|
|
|
|
|
|
Sujana Alluru wrote: Yes its almost like recreating the application You would be programming all those routines that are now Macro's and formulas.
Sujana Alluru wrote: looking for option where we can embed the excel into the application Ehr, Microsoft has the copyrights to Excel.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You're not describing a "requirement"; you're describing a solution; and perhaps not the best one.
"Users" don't formulate these types of "requirements"; IT does.
Sounds like you're trying to possibly minimize Excel licensing fees or avoid using Excel altogether. If not, there are better "solutions"; e.g. SharePoint; Excel services; etc.
|
|
|
|
|
Gerry,
It's the requirement. Where an age old traditional excel application to be converted/ redesigned as web application with out changing the look and feel much, as the client is not willing in changing the same old excel interface.
I'm exactly not sure whether this can be done by a grid. and I have big question of retrieving the data, formulas and macros of the excel application as is.
It's urgent and pls help on this.
|
|
|
|
|
The "requirement" seems to be to be able to access Excel workbooks over the internet (and not to eliminate Excel).
As Pete said, you can upload Excel workbooks to SharePoint and share them between users.
You get Excel "look-and-feel" and a "web application".
A "SharePoint Online" subscription starts at less than $5.00 per month where you can do a proof-of-concept. The Excel / Office components may add a few $ per month but you can cancel any time. Note that "external users" with read-only access to your SharePoint site cost nothing.
I'd be surprised if you could not get this up and running in less than a week (and no C# needed. Sorry).
|
|
|
|
|
of course it's some thing like accessing the excel work books over internet, along with some functionality enhancements like logs, database interactions, monitoring the data change as well.
I'm trying this in jquery, using the jquery.sheet plugin. which can be used to create a sheet just like excel. but here the problem is I'm not able to do much changes when the application demands any, as this is a free plugin and not much documentation is provided.
|
|
|
|
|
Ah, now I see. You're representing a "vendor".
|
|
|
|
|
The easiest way to do this is to use Sharepoint, and save your Excel spreadsheet as an Excel Web App[^].
|
|
|
|
|
Thank you all for your suggestions. Let me put this (Share Point) to my manager.
|
|
|
|
|
Another possibility:
1. Keep in the backend "Your Excel Sheet based service". This can be implemented in you web server as a singleton (for perfomance) object that uses Interop for interacting with you Excel sheet.
2. Your web app, queries "Your Excel Sheet based service" to get the grid data to send to the browser
3. The browser displays your data using one of the Javascript grids.
4. The user modifies the data using the Javascript grid editor.
5. Any change is sent as a browser request to your web app (via Ajax or page reload)
6. Your web app, updates "Your Excel Sheet based service", so Excel applies the macros and calculations, and the new values are sent to the web browser on the request response (Ajax or page content)
Conceptually you get everything, and the best of both worlds. The good part is that you do not need to reimplement all your Excel logic (macros, formulas,...), the bad part is that you need to reimplement all the interface to reach this logic (grid cells paradigm, REPL cycle, ...)
Although it can be done, in practice this is far from an ideal solution as:
- An strategy is needed to avoid multiple users locking your Excel resource
- Using interop in the server might lead to memory leaks and stability issues. Also it can easily become a CPU resource hog.
- User interface and usability is greatly dependant on the chosen grid, and might depart greatly from Excel look and feel
Although the cons can easily overweigth the pros, depending on your requirements (number of users, complexity of Excel logic..), budget, resources and available time can be a way to go.
|
|
|
|
|