|
First of all - what's the exception? Secondly, there's no ExecuteNonScalar command (I assume you mean ExecuteScalar here). Third, retrieve the value into an object, and then use int.TryParse to attempt to convert the object into an integer.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
If you're querying an int from a database with ExecuteScalar , then the value is already an int , you don't need to convert it. All you need to do is use a cast to unbox it:
int x = (int) cmd.ExecuteScalar() ;
|
|
|
|
|
Please reconfirm the method
|
|
|
|
|
Hi,
Has any one every used the latest version of the patterns from www.dofactory.com? I am working through their code and some stuff don't make sense to me. When I enter the service layer from the client side (code behind), the call a mathod like GetProduct, and this method will return a ProductResponse. In this method the GetProduct method is called from the ProductDao and it returns a Product object. Then the Product's properties are assigned to that of a data transfer object, and this is returned.
Can someone please try and explain why they would use it like this, especially requests and responses? Normally requests and responses are used with web services, but they don't use web services here. Is this a new way of doing things?
Regards
Brendan
|
|
|
|
|
I've not looked at the most recent patterns but judging by the fact they've got a service layer it implys the design would be using a web service or WCF. It is possible that the design will be for a multi tiered app with a service but for simplicitys sake for the setup they've made it a logical service layer rather than physical.
|
|
|
|
|
Thanks. How do you rate the previous design that they used? Do you think it is good implementing? In the newer version they had a service, but you don't have to use it. You can disable it. I disabled it, but there is still the request and response objects.
|
|
|
|
|
It helps to understand what the service layer actually is. It's not tied to being a web/remoting layer - instead, the service layer is the layer that coordinates the interactions of lower levels to produce a response.
Consider, for instance, a holiday booking system - you might have a service that books a holiday at a foreign destination. Behind the scenes, the service layer talks to the resort booking management system, the flight reservation systems and car-hire systems. As far as you are concerned though - you've talked to one thing, and it has taken care of all the lower level detail work. Where this layer really comes into its own, is that it can control the transaction lifetime; in other words if one part fails to commit, you want the whole thing to fail to commit - across the separate systems, who wants to book a car if the hotel reservation failed.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hey Pete,
Thanks for your reply. This service concept is new to me, so I am trying to understand why it is necessary if I don't make use of an web services at all. Is it maybe best practices to do it this way if it is just a plain ASP website? The DoFactory solution made use of web services, but they said that if you don't want to make use of the web services then I could make a couple of changes not make use of the web services. Is the service layer still required if I do not make use of web services? Because the service layer calls the facade objects, I can always bypass the service layer and call the facade objects directly from code behind?
Brendan
|
|
|
|
|
I think they may have confused the issue with the whole web service thing. As I stated, the service layer is a coordinating layer - see the whole transaction idea.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Brendan,
I have to ask why are you not contacting DoFactory with this question : don't they have support resources, or a forum ?
I am not trying to "put you down" or insult you by asking this !
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hey Bill,
I do. I normally send them a mail when I have questions but they respond like 1% of the time. This service concept is new to me, so I am trying to understand why it is necessary if I don't make use of an web services at all.
Brendan
|
|
|
|
|
Hi All,
I just want to get some advice on software startups. First of all me and 2 other classmates have finished college and would like to get work, but since we dont have any commercial experience , it is difficult. We all studied c# and got high marks , and now we are thinking of starting our own business in software development to get experience. We intend to initially specialize in software testing ,etc and be a provider for other web/software companies who wish to outsource coding to people like us.However I am unsure as to how receptive these companies may be.
I would like to find out:
a) Is it a good arrangement to work in a team. And
b) To know if doing testing (as a group) for software companies would be a way to start off a programming career and to get experience on the way to getting a job.
c) Is it a risky proposition?
Thanks all.
|
|
|
|
|
Hi,
I don't think this belongs in the C# forum. We have a "Running a Business" forum for this kind of questions. There isn't much traffic, but it is rather good IMO.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
a) Probably.
b) Developers can, and should, test. Testers shouldn't code. Formal software testing is a real job in itself and shouldn't be seen as a stepping stone into development.
c) For fresh grads, yes.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
i have to fetch data from excel file and display it in a grid...user can choose the columns to display in grid as well as their sequence...hw to do it?
|
|
|
|
|
Here is the walkguide i can offer
1)First transfer excel content to a datatable using oledb.
2)Bind datatable's columns property to a listbox and allow users to choose multiple
3)Generate gridview column for each selected datatablecolumn from listbox/
4)Bind the data to grid.
I hope it helps. If you have any problem i'll try to explain with code.
|
|
|
|
|
thanks can u plz show me some code
|
|
|
|
|
Here is the code hope helps.
public string GetExcelConnectionString(string fileName)
{
if (fileName.EndsWith("xls"))
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + @";Extended Properties=""Excel 8.0;IMEX=1""";
}
else
{
return @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + @";Extended Properties=""Excel 12.0 Xml;HDR=YES;""";
}
}
OpenFileDialog ofd = new OpenFileDialog();
ComboBox cmbTables = new ComboBox();
ListBox lstColumns = new ListBox();
Button btnShowInGrid = new Button();
DataGridView dgv = new DataGridView();
DataTable dt = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
lstColumns.SelectionMode = SelectionMode.MultiSimple;
dgv.AutoGenerateColumns = false;
btnShowInGrid.Text = "Show In Grid";
btnShowInGrid.Click += new EventHandler(btnShowInGrid_Click);
this.Controls.Add(dgv);
this.Controls.Add(btnShowInGrid);
this.Controls.Add(lstColumns);
this.Controls.Add(cmbTables);
lstColumns.Dock = DockStyle.Top;
cmbTables.Dock = DockStyle.Top;
btnShowInGrid.Dock = DockStyle.Top;
dgv.Dock = DockStyle.Fill;
cmbTables.SelectedIndexChanged += new EventHandler(cmbTables_SelectedIndexChanged);
ofd.ShowDialog();
OleDbConnection conn = new OleDbConnection(GetExcelConnectionString(ofd.FileName));
conn.Open();
DataTable tables = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
conn.Close();
cmbTables.DataSource = tables;
cmbTables.DisplayMember = "TABLE_NAME";
cmbTables.ValueMember = "TABLE_NAME";
}
void btnShowInGrid_Click(object sender, EventArgs e)
{
dgv.Columns.Clear();
foreach (object o in lstColumns.SelectedItems)
{
DataGridViewTextBoxColumn c = new DataGridViewTextBoxColumn();
c.DataPropertyName = o.ToString();
dgv.Columns.Add(c);
}
dgv.DataSource = dt;
}
void cmbTables_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(GetExcelConnectionString(ofd.FileName));
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + ((DataRowView)cmbTables.SelectedItem)["TABLE_NAME"].ToString() + "]", conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
conn.Close();
lstColumns.Items.Clear();
foreach (DataColumn clmn in dt.Columns)
{
lstColumns.Items.Add(clmn.ColumnName);
}
}
|
|
|
|
|
|
While desirialising byte[], an error message as
"Unable to translate the byte[DO]at index 1 from specified page to unicode ".
Plz suggest me some solution.
|
|
|
|
|
Hi all
I'm working in listbox. I have to store multiple items from listbox into database.
Plz help me with some sample code
Thanks in advance.....
Elizabeth..
|
|
|
|
|
Here is a peace of code, did not test it but it sould work:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace test
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void Button1Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"User ID=username; Password=pass; Initial Catalog=databasename; data source=localhost");
SqlCommand cmd = conn.CreateCommand();
foreach(object i in listBox1.SelectedItems)
{
cmd.CommandText = "INSERT INTO TableName (columnName) VALUES('"+i.ToString()+"')";
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
}
|
|
|
|
|
Hi,
In my application.i want to connect to server and read the files drive by drive.
I tried in local by using System.IO namespace and succeeded.
Could any body help me to connect server and retreive file list.
Shall i need to use RDC or any other option?
thanks in advance
Bobby
Have a Nice Day Dudes
|
|
|
|
|
If you dont know the names of drives you can get the names of drives using System.Management namespace with wmi.
After that i assume you have sharings on folders. then all you have to do is using a code like below
System.IO.Directory.GetFiles(@"\\10.10.0.50\d$");
Also you can use getdirectories or similar methods like this.
|
|
|
|
|
HI Tamer,
THank u very much
Till now am using Directoryinfo class,so am unable to solve this.
My remote system is provided by Username and password.so when i tried i got the following error
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path)
at FileSearcher.Searcher.SearchThread()
is there any way to pass the credentials and then access the remote system.could u pls suggest me?
thanks in advance
Have a Nice Day Dudes
|
|
|
|