|
Thanks, works 100%
He who laughs last is a bit on the slow side
|
|
|
|
|
Hi
I have exported pubs authors table into flatfile. I am trying to import the same flat file data into dataset in C#. Could you any one help me please.
Data from flat file to Dataset(same format like authors table).
kesavan
|
|
|
|
|
The following works for an Excel worksheet:
this.dataSet = GetDataset(worksheet, "BookName");
private DataSet GetDataset(Excel.Worksheet worksheet, string startElement)
{
StringBuilder stringBuilder = new StringBuilder();
XmlTextWriter xmlTextWriter = new XmlTextWriter(new StringWriter(stringBuilder));
xmlTextWriter.WriteStartDocument();
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.Indentation = 3;
int row = 2;
Array rowValues = (Array)worksheet.get_Range("A" + row.ToString(), "C" + row.ToString()).Cells.Value2;
string Col1 = GetString(rowValues.GetValue(1, 1));
string Col2 = GetString(rowValues.GetValue(1, 2));
string Col3 = GetString(rowValues.GetValue(1, 3));
DataSet ds = new DataSet("table");
xmlTextWriter.WriteStartElement(startElement);
if (Col2 == string.Empty)
{
DataTable dataTable = new DataTable("row");
dataTable.Columns.Add("Col1");
dataTable.Columns.Add("Col2");
dataTable.Columns.Add("Col3");
dataTable.Rows.Add(new object[] { null, null, null });
ds.Tables.Add(dataTable);
return ds;
}
while (Col2 != string.Empty)
{
xmlTextWriter.WriteStartElement("row");
xmlTextWriter.WriteElementString("Col1", Col1);
xmlTextWriter.WriteElementString("Col2", Col2);
xmlTextWriter.WriteElementString("Col3", Col3);
xmlTextWriter.WriteEndElement();
row++;
rowValues = (Array)worksheet.get_Range("A" + row.ToString(), "C" + row.ToString()).Cells.Value2;
Col1 = GetString(rowValues.GetValue(1, 1));
Col2 = GetString(rowValues.GetValue(1, 2));
Col3 = GetString(rowValues.GetValue(1, 3));
}
xmlTextWriter.WriteEndElement();
xmlTextWriter.Flush();
xmlTextWriter.Close();
XmlTextReader xmlReader = new XmlTextReader(stringBuilder.ToString(), XmlNodeType.Element, null);
ds.ReadXml(xmlReader);
return ds;
}
For a flat file get rowValues array as follows:
StreamReader inStream = new StreamReader(filePath);
line = inStream.ReadLine();
while(inStream.Peek() >= 0)
{
line = inStream.ReadLine();
string[] rowValues = line.Split(new Char [] {','});//assumes flat file is comma delimited
}
inStream.Close();
Col1 = rowValues[1];
Col2 = rowValues[2];
Col3 = rowValues[3];
|
|
|
|
|
I am trying to connect SQL Server from my computer (named TANKIMHUY.kimhuy.com.vn) to my colleague's computer (named PHANTAM.kimhuy.com.vn). Of course both computers are clients.
SQL Server instance is installed in two machines.
I open SqlConnection's wizard dialog, I see two names( (local) and PHANTAM) in Server Name comboBox.
When I choose PHANTAM as a server name and fill usename: sa password: sa, but I see an empty list of databases instead of a list of available databases such as Northwind, ... in SQL Server 2000
I am very confused what wrong I have. Someone help me show the available databases or how to connect SQL Server from client machine to client other in C#
Thank you very much.
-- modified at 1:57 Wednesday 17th January, 2007
|
|
|
|
|
Have you check the basics?
- Have you got the correct credential to conect to his database? (Try with both SQL credential and microsoft autentification)
- Has your colleague given you the correct privileges to access his database?
- have you try to create a OBDC connection to his PC (That will also validate the connection)
- Check with your IT that they have not restricted some connections...
Elephant
|
|
|
|
|
Hi All,
I have block of code and i want to execute that code only once when we run(execute) a program 4 first time in C#.net
pls give a sol ,I wiil be looking for u r reply,
regards,
VINAY,
pune
|
|
|
|
|
If you are using asp.net code behind c# means put the code in postback event.
kesavan
|
|
|
|
|
I'd say your best bet would be to create a registry entry, firstRun, 0-1.
Then check that registry value to check if it is your apps first run, if it is execute block of code, set value to 0 for false, next time you start up the program it will check the value and see firstRun is false and the skip the block of code.
Hope that helps.
He who laughs last is a bit on the slow side
|
|
|
|
|
hi Nero ,
Thamks 4 u r reply , But Iam not awareof registry entry concept,Could u pls tell me detailed how do i do it.
|
|
|
|
|
|
pls try nt 2 use smsspk in da 4rm. s'not a mob fone.
|
|
|
|
|
there is a image on a click on one part of an image i have to connect a page
and another part i have to do connect someother page
how to do this piece of work
thanking u
|
|
|
|
|
Split the image in two parts and put two image controls on the page and write your code accordingly.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
I was wondering if it is possible to compare file attributes over the internet?
|
|
|
|
|
Hi Frnds,
i have a issue in C#.
when i run some code which i downloaded from internet i got the error like.
"visual studio can not start debugging because the debug target 'so so so so path .exe' is missing. please build the project and retry, or set the output path and assemblyname properties appropriately to point at the correct location for the target assembly."
i dont know how to resolve..i search on internet since 1 week still i m not able to get the solution...
i post in forum also asked some developers but still i am not getting the solutions.
i m not able to run project...because in Bin directory there is no (.EXE) it is not necessary that we must have (*.exe) in BIN directory.
in my some program if i delete the Bin Folder and again run then it will automatically created BIN folder and (.exe) file also in those project i didnt get error that you have no (.exe)
in some program if i click on the Rebuil System. then it delete (.exe) and the program will not run and get the same error like "visual studio can nt start debugging ......................"
i know this problem is small for all of you... please try to solve and give me the proper suggestion
Awaiting for your positive reply..
patelhiren20@rediffmail.com
Thanks & Regards
Hiren Patel
patelhiren20@rediffmail.com
hiren
|
|
|
|
|
If there's no exe, then your build has failed. That's what happens when you grab code at random and add it to your project.
What is the error with the actual code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Tools->Options->Projects and Solutions->Build and run:
set: "On Run, when projects are out of date:" to: "Always build"
set: "On Run, when build or deployment errors occur:" to "do not launch"
life is study!!!
|
|
|
|
|
Hi,
I am having a WCF service which exposes two functions. One returns a string and another returns an array of custom object Employee. Employee class is a DataContract and all it contains is simple premitive data types marked as DataMember. First method works fine but I am not able to get the second method GetEmployeeArray() working.
Any clues how to pass complex data types with premitive data members in WCF?
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
Just curious but what type of formatter are you using. I have had success using the BinaryFormatter but it has a bit different syntax from the Messaging namespace for MSMQ. I was passing a generic list and it was working pretty good. Can you post a code bit of code so I can see what it looks like?
|
|
|
|
|
Thanks for the quick reply Kevin.
Here is my code.
My Service Contract looks like this.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.ServiceModel;<br />
using System.Data;<br />
<br />
namespace WCFService<br />
{<br />
[ServiceContract] <br />
public interface IWCFService<br />
{<br />
[OperationContract]<br />
string GetSystemIPAddress();<br />
<br />
[OperationContract]<br />
object[] GetEmpolyeeArray();<br />
}<br />
}<br />
The class implementing the service contract looks like this.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using SystemInfo;<br />
using System.Data;<br />
using System.ServiceModel;<br />
<br />
namespace WCFService<br />
{<br />
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]<br />
public class WCFService : IWCFService<br />
{<br />
#region IWCFService Members<br />
<br />
public string GetSystemIPAddress()<br />
{<br />
return new SystemInfo.SystemInfo().GetIPAddress();<br />
}<br />
<br />
public object[] GetEmpolyeeArray()<br />
{<br />
DataSet ds = new SystemInfo.SystemInfo().GetEmployeeList();<br />
Employee[] emps = new Employee[ds.Tables[0].Rows.Count];<br />
int index = 0;<br />
foreach (DataRow row in ds.Tables[0].Rows)<br />
{<br />
emps[index] = new Employee();<br />
emps[index].EmployeeID = Convert.ToInt32(row["EmployeeNo"]);<br />
emps[index].Experience = Convert.ToDecimal(row["Experience"]);<br />
emps[index].FirstName = row["FirstName"].ToString();<br />
emps[index].LastName = row["LastName"].ToString();<br />
emps[index].MiddleName = row["MiddleName"].ToString();<br />
emps[index].Qualification = row["Qualification"].ToString();<br />
index++; <br />
}<br />
return emps;<br />
}<br />
#endregion<br />
}<br />
}<br />
My DataContract is this
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.ServiceModel;<br />
using System.Runtime.Serialization;<br />
<br />
namespace WCFService<br />
{<br />
[DataContract]<br />
public class Employee<br />
{<br />
[DataMember]<br />
public int EmployeeID;<br />
[DataMember]<br />
public string FirstName;<br />
[DataMember]<br />
public string MiddleName;<br />
[DataMember]<br />
public string LastName;<br />
[DataMember]<br />
public decimal Experience;<br />
[DataMember]<br />
public string Qualification;<br />
}<br />
}<br />
My Java client is like this:
<br />
package wcfjavaclient;<br />
<br />
<br />
public class Main {<br />
<br />
<br />
public Main() {<br />
}<br />
<br />
<br />
public static void main(String[] args) {<br />
try {
WS.WCFService service = new WS.WCFService();<br />
WS.IWCFService port = service.getBasicHttpBindingIWCFService();<br />
java.lang.String result = port.getSystemIPAddress();<br />
System.out.println("Result = "+result);<br />
} catch (Exception ex) {<br />
} <br />
} <br />
}<br />
Please let me know if you want to see anything more. First method GetSystemIP works fine. But second one does not.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
Ok don't take this as fact I am working through the WCF myself. I had very similar issues so I experimented with the [XmlSerializerFormat] attribute for the service contract and got better results. I am not sure what the precise issue is but it seems to be related to the serilization of the array. I used a generic list instead of an array but I cannot see that that would make any difference.
|
|
|
|
|
Hi Kevin,
Thanks again and I am trying with [XmlSerializerFormat] attribute. But I do not know it is showing some wierd error like this.
Web service client can not be created by JAXWS:wsimport utility.
Reason: duplicate "message" entity: "IWCFService_GetSystemIPAddress_InputMessage"
My WSDL is like this.
<br />
<small><br />
<pre><br />
<?xml version="1.0" encoding="utf-8" ?> <br />
- <wsdl:definitions name="WCFServiceImplement" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="WCFServiceNamespace" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"><br />
<wsdl:import namespace="WCFServiceNamespace" location="http://10.34.34.241:8578/WCFService?wsdl=wsdl0" /> <br />
- <wsdl:types><br />
- <xsd:schema targetNamespace="http://tempuri.org/Imports"><br />
<xsd:import schemaLocation="http://10.34.34.241:8578/WCFService?xsd=xsd0" namespace="http://tempuri.org/" /> <br />
<xsd:import schemaLocation="http://10.34.34.241:8578/WCFService?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> <br />
</xsd:schema><br />
</wsdl:types><br />
- <wsdl:message name="IWCFService_GetSystemIPAddress_InputMessage"><br />
<wsdl:part name="parameters" element="tns:GetSystemIPAddress" /> <br />
</wsdl:message><br />
- <wsdl:message name="IWCFService_GetSystemIPAddress_OutputMessage"><br />
<wsdl:part name="parameters" element="tns:GetSystemIPAddressResponse" /> <br />
</wsdl:message><br />
- <wsdl:portType name="IWCFService"><br />
- <wsdl:operation name="GetSystemIPAddress"><br />
<wsdl:input wsaw:Action="http://tempuri.org/IWCFService/GetSystemIPAddress" message="tns:IWCFService_GetSystemIPAddress_InputMessage" /> <br />
<wsdl:output wsaw:Action="http://tempuri.org/IWCFService/GetSystemIPAddressResponse" message="tns:IWCFService_GetSystemIPAddress_OutputMessage" /> <br />
</wsdl:operation><br />
</wsdl:portType><br />
- <wsdl:service name="WCFServiceImplement"><br />
- <wsdl:port name="NetTcpBinding_IWCFService" binding="i0:NetTcpBinding_IWCFService"><br />
<soap12:address location="net.tcp://10.34.34.241:8999/WCFService" /> <br />
- <wsa10:EndpointReference><br />
<wsa10:Address>net.tcp:
</wsa10:EndpointReference><br />
</wsdl:port><br />
- <wsdl:port name="BasicHttpBinding_IWCFService" binding="i0:BasicHttpBinding_IWCFService"><br />
<soap:address location="http://10.34.34.241:8888/WCFService" /> <br />
</wsdl:port><br />
</wsdl:service><br />
</wsdl:definitions><br />
</pre><br />
</small><br />
Any idea?
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
Hi Kevin,
Finally I have done with it. The problem is not with WCF and [XmlSerializerFormat] attribute is also not required for service contract. The key concept is JAVA client can not get an Array of object of DataContract member. I have tried several ways but Array of Employee class never worked out. I tried it with List<employee> and it worked very fine.
Thanks for your prompt response and guidance.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
Hi,
I am trying to open a file that not exit.
so want i want if file not there it should create a file with same name.
Thanks.
|
|
|
|
|
give a file name to openFileDialog
you can confirm if the file exist
if not you can create the same name file.
I want to make some friends here
|
|
|
|