|
You don't loop through the rows. Instead you define a datasource for the DataGridView, create a column in it and define the column from the datatable to show. For example something like this:
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "ColumnInDataTable";
column.HeaderText = "Header";
column.Name = "somename";
this.dataGridView1.Columns.Add(column);
this.dataGridView1.DataSource = dt1;
Of course you are aware that you can do this also in the designer.
|
|
|
|
|
Hi.......
U have lots of options to do this....
First One:
By Using BindingSource:::>> dataGridView1:>properties:>Choose Datasource:>{If u have already one then select it otherwise select Add Project Datasource}
If u cann't follow this Just message me!!!!!!
Second One:
fill dataset according to ur needs....
DataView dv = new DataView(dt.Tables["Specify table name here"]);
dataGridView1.DataSource = dv;
dataGridView1.Refresh();
{Remember Donn't Add Columns to DataGridView }
try this...... and reply me....
|
|
|
|
|
Hi Everyone,
I would just like to ask a question in relation to calling a web service.
I know how to call a web method when the return value is a string or an integer, however I am having difficulty in returning a dataset method that is in a class.
The following error gets returned
Error 1 Cannot implicitly convert type 'System.Data.DataSet' to 'ConnectToDB'
and i have tried several times to rectify this by changing the return value to string yet it relays a similar message to the above. . I guess my main query is , how do i create the web method so that it can return a dataset from the database?
Would someone be able to assist? Many Thanks. The code is below.
<br />
<br />
using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Xml.Linq;<br />
using System.Data.SqlClient;<br />
public class ConnectToDB<br />
{<br />
public ConnectToDB()<br />
{<br />
}<br />
<br />
public static DataSet FilterCustomersByCountry(string country)<br />
{<br />
<br />
string query = "SELECT DISTINCT COUNTRY FROM CUSTOMERS WHERE COUNTRY LIKE" + "'"+country+"'";<br />
using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\MyCompany.MDF;Integrated Security=True;User Instance=True"))<br />
{<br />
DataSet ds = new DataSet();<br />
<br />
SqlDataAdapter adapter = new SqlDataAdapter(query, conn);<br />
adapter.Fill(ds, "Customers");<br />
<br />
return ds;<br />
<br />
}<br />
}<br />
}<br />
<br />
<br />
using System;<br />
using System.Collections;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Services;<br />
using System.Web.Services.Protocols;<br />
using System.Xml.Linq;<br />
using System.Data.SqlClient;<br />
using System.Data.Sql;<br />
<br />
[WebService(Namespace = "http://AJAXAutocomplete.org/",Name="AutocompleteVersion1")]<br />
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
public class AutoComplete : System.Web.Services.WebService {<br />
<br />
public AutoComplete () {<br />
<br />
}<br />
<br />
[WebMethod] <br />
public ConnectToDB SuggestionsFromDB(string country) <br />
{<br />
return ConnectToDB.FilterCustomersByCountry(country);<br />
}<br />
<br />
}<br />
<br />
<br />
|
|
|
|
|
If you want to return a dataset from the web method, use something like:
[WebMethod]
public System.Data.Dataset SuggestionsFromDB(string country)
{
return ConnectToDB.FilterCustomersByCountry(country);
}
The ConnectToDB is your class for getting the data.
Also note that never use concatenation in the sql statement in a situation like this. You're fully open to SQL injections. So your query should be:
string query = "SELECT DISTINCT COUNTRY FROM CUSTOMERS WHERE COUNTRY LIKE @Country";
and then you define a SqlParameter[^] to give the query a value.
|
|
|
|
|
Awesome answer Mika, Thanks very much for your help and the heads up about the SQL injection.
Best Regards
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi,
I have a situation like this:
I have a web-page where several "textboxes" and have an Excel file.
I have no direct access to web-page, that is, I can only open it in web-browser - https://
I need to copy data from Excell cell into textbox, and push an ENTER button. Of course, the web-page is open at the moment.
I know how to copy data from Excel into html, but have no experience how to copy into textbox in an open IE. and how to push link/button in IE.
could anybody help ???
Respectfully,
Exceter.
|
|
|
|
|
the article "Minimize window to system tray By Elroy Dsilva" was great in minimizing an application but it missed how to add menus to the icon like restore exit.. and others... where should i have to write the menu codes for that..... thans...
|
|
|
|
|
You'll need to add a contextMenu to the notifyIcon. Works the same as adding a mainmenu.
Good luck
I are troll
|
|
|
|
|
|
helu.. can a windows service be configured to display a windows control such as a message box or text box for the user... thans ...
|
|
|
|
|
In short no. Service should never interact with desktop directly and depending on windows version it's impossible.
However, you can write a desktop application to communicate with the service and place that application for example in system tray. This application can then show a messagebox to the user based on the information received from the service.
|
|
|
|
|
thns very much for the solution...
|
|
|
|
|
|
Hi,
I have a function (Server Side) which is used to fill the values in dropdownlist but I want to call the function from javascript.I am using c#.net.
Regards,
Atul Rane
|
|
|
|
|
I just checked, and you have posted in the ASP.NET forum before, so you must know it exists.
You're describing AJAX. AJAX is a way for a web page to call the code behind and retrieve data from it without refreshing the entire page.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks Christian for your reply,
Can you give me some web links where i can get more detail about this.
Regards,
Atul Rane
|
|
|
|
|
i am a begginer. so thanks if u answer my question in a simple way. i had a form and i wanna add an inherited form by write code. i dont know how?! and i dont know where the code should sit and placed!
[]D @ []v[] []D @ []v[]
|
|
|
|
|
If you want to inherit a form from another form you do something like this (creates a new MyForm class inherited from System.Windows.Forms.Form):
public class MyForm : System.Windows.Forms.Form {
public MyForm() : base() { }
...
}
This seems like a good tutorial to start with: .NET Tutorial for Beginners[^]
|
|
|
|
|
thanks mika, but i like to deal with someone like u to learn it better, if it's no problem.
[]D @ []v[] []D @ []v[]
|
|
|
|
|
These forums are to help people who for example get stuck with a specific problem. All people expect that the person who asks a question has the basic knowledge about the environment he/she is working with. Many times people are given links to shortcuts or books that are very useful, but after that it's expected that the person reads the given information and tries to learn the environment (C# in this case).
So in short the purpose of these forums is not to educate people starting from beginning, but to help people with specific, clearly asked questions.
I'm sure that if you read the document I posted, you'll get a good start to C# inheritance along with other fields of programming in C#. Also you should consider buying a good book or two. Think of it like an investment to yourself.
|
|
|
|
|
Thanks for ur advice. Certainly.
[]D @ []v[] []D @ []v[]
|
|
|
|
|
Nice Advice.....
i will follow this....
|
|
|
|
|
Buy a book on C# and read it. However, what do you mean by 'add an inherited form by write code' ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i mean create an inherited form in code with visual c# ....! i hope u understand what i say!
[]D @ []v[] []D @ []v[]
|
|
|
|