Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Mala pomoc oko C#, UPOMOOOC

[es] :: .NET :: .NET Desktop razvoj :: Mala pomoc oko C#, UPOMOOOC

[ Pregleda: 3086 | Odgovora: 14 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Mala pomoc oko C#, UPOMOOOC03.06.2005. u 13:24 - pre 198 meseci
Kako bi trebao otprilike da glasi kod, ispisan u C#, koji radi sledece:
kada kliknem na button1 Refresh, proverava se sta je uneto u textBox1, koji je predvidjen za unos OrderID-a. Zatim se ispisuje ShipName i OderDate koji odgovaraju tom OrderID-u u dva posebna textBox-a (textBox2 i textBox3)?
Ono sto me najvise buni kod ovog problema je kako da definisem da Refresh "gleda" sta je uneto u textBox1.

Pocetnik sam, pa Vas molim za razumevanje :-)

[Ovu poruku je menjao Shejn dana 05.06.2005. u 14:17 GMT+1]
 
Odgovor na temu

vekica
Veroljub Zmijanac
beograd

Član broj: 29640
Poruke: 128
*.dialup.sezampro.yu.

ICQ: 330192115
Sajt: www.veroljub.blogspot.com


Profil

icon Re: Mala pomoc oko C#03.06.2005. u 16:29 - pre 198 meseci
if (textbox1.text != "") //nije prazan text box
{

textbox2.text = VratiIzBazeShipName(textbox1.text);
textbox3.text = VratiIzBazeOrderDate(textbox1.text);
}

//potpis metoda je ovakav
private string VratiizBAzeShipName(string ORderID)
{
//ovde implemetiras
//pa onda izvuces iz baze podataka ili vec cega podakte za taj id
}


ovo ti je samo jedan od bezbroj nacina. ja bih ovako uradio
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#04.06.2005. u 15:17 - pre 198 meseci
Jel bi moglo ovo malo detaljnije:
Citat:
vekica
private string VratiizBAzeShipName(string ORderID)
{
//ovde implemetiras
//pa onda izvuces iz baze podataka ili vec cega podakte za taj id
}


Sta je sa Button-om Refresh?
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#05.06.2005. u 13:03 - pre 198 meseci
pokusao sam nesto ovako :

private void button1_Click(object sender, System.EventArgs e)
{
if (textBox1.Text != " ") //nije prazan text box
{
textBox2.Text =VratiIzBazeShipName(textBox1.Text);
textBox3.Text =VratiIzBazeOrderDate(textBox1.Text);
}
}

private string VratiIzBazeShipName(string ORderID)
{
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText =" SELECT ShipName FROM Orders WHERE OrderID='"+ORderID+"'";
SqlDataReader dataReader = dataCommand.ExecuteReader();
while(dataReader.Read())
{
string ShipName = dataReader.GetString(8);
Console.WriteLine(ShipName);
}
dataReader.Close();
}

private string VratiIzBazeOrderDate(string ORderID)
{
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText =" SELECT OrderDate FROM Orders WHERE OrderID='"+ORderID+"'";
SqlDataReader dataReader = dataCommand.ExecuteReader();
while(dataReader.Read())
{
DateTime OrderDate = dataReader.GetDateTime(3);
Console.WriteLine(OrderDate);
}
dataReader.Close();
}

ali mi prijavi greske :



'WindowsApplication4.Form1.VratiIzBazeShipName(string)': not all code paths return a value
'WindowsApplication4.Form1.VratiIzBazeOrderDate(string)': not all code paths return a value
 
Odgovor na temu

dusty
Predrag Glumac
Zemun, Srbija

Član broj: 15383
Poruke: 549
213.137.127.*

Sajt: www.mika.rs


+6 Profil

icon Re: Mala pomoc oko C#, UPOMOOOC05.06.2005. u 14:45 - pre 198 meseci
Fali ti return na kraju metoda VratiIzBazeOrderDate i VratiIzBazeShipName, posto vracaju vrednosti tipa string. Ili stavi da su metode void.
America national sport is called baseballs. It very similar to our sport, shurik, where we take dogs, shoot them in a field and then have a party.
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC05.06.2005. u 18:56 - pre 198 meseci
ako stavim ovako :
while(dataReader.Read())
{
string ShipName = dataReader.GetString(8);
Console.Write(ShipName);
return(ShipName);
}
javlja mi iste greske

ako stavim ovako:

while(dataReader.Read())
{
string ShipName = dataReader.GetString(8);
Console.Write(ShipName);
}
return(ShipName);
dataReader.Close();


javlja mi:

The name 'ShipName' does not exist in the class or namespace 'WindowsApplication4.Form1'
 
Odgovor na temu

spartak

Član broj: 5625
Poruke: 631
*.dialup.sezampro.yu.



+3 Profil

icon Re: Mala pomoc oko C#, UPOMOOOC05.06.2005. u 21:20 - pre 198 meseci
Druze, greska ti je u drugom slucaju sto deklarises promenjivu u okviru while bloka, pa je onda pozivas van tog scope gde vise ne postoji (to jest nikad nije ni postojala).

Code:

string ShipName = String.Empty; // ovde van petlje
while(dataReader.Read())
{
  ShipName = dataReader.GetString(8); 
  Console.Write(ShipName);
}
return(ShipName);
dataReader.Close();


Sto se tice prvog slucaja, nije mi jasno sta ce return u okviru while petlje?
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC05.06.2005. u 23:45 - pre 198 meseci
Spartak, ovaj deo:

Citat:


Code:

string ShipName = String.Empty; // ovde van petlje
while(dataReader.Read())
{
  ShipName = dataReader.GetString(8); 
  Console.Write(ShipName);
}
return(ShipName);
dataReader.Close();



nece odraditi posao :-( , vraca mi gresku:

A local variable named 'ShipName' cannot be declared in this scope because it would give a different meaning to 'ShipName', which is already used in a 'parent or current' scope to denote something else.

Mozda sama postavka resenja nije dobra, odnosno mozda postoji neko elegantnije resenje pa ako neko ima neki predlog neka ga slobodno izlozi ovde.

Hvala ljudi !
 
Odgovor na temu

Čarli
BG

Član broj: 38963
Poruke: 6
*.wireless.org.yu.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC06.06.2005. u 07:46 - pre 198 meseci
Na dobrom si putu, samo što trebaš malo da pogledaš kako se deklarišu promenjive, te kakav je njihov doseg ( ili što neko reče gore --- scope ).
Poslednja poruka ti kaže da si npr. 2 puta u kodu upotrebio, npr.

string promenjiva;

potom si ( unutar istog ili nekog od blokova iznad koji obuhvataju tekući ) ponovno napisao, tj. deklarisao istu varijablu kao i prethodni puta ---

string promenjiva;

To nije moguće, tj. dvostruka deklaracija i kompajler ti to saopštava. Dakle:

1. 'promenjivu' navođenjem njenog tipa ( u ovom slučaju string ) možeš deklarisati samo jednom;
2. koristiti je možeš ( dodeljivanjem nje same drugoj promenjivoj istog tipa, ili pak dodeljivanjem njoj vrednosti istog tipa ) beskonačno - 1 puta.
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC06.06.2005. u 10:36 - pre 198 meseci
Carli hvala na objasnjenju, ali vise bi mi znacilo da si mi dao neki predlog za resenje gore pomenutog problema.

U svakom slucju hvala i za ovo.
 
Odgovor na temu

djordjeno
Lj Slovenia / Srbija

Član broj: 35204
Poruke: 326
195.178.55.*

Sajt: www.mobitel.si


+39 Profil

icon Re: Mala pomoc oko C#, UPOMOOOC06.06.2005. u 19:06 - pre 198 meseci
Čarli ti je dobro rekao, pogledaj da li si negde gore i kodu stavio neku promenljivu sa imenom 'ShipName'. Cini mi se da ako koristis Northwind database primer da u njemu imas neku tabelu koja ima ime ShipName ili ima kolona sa tim imenom. Inace, ovo ostalo sto je gore navedeno bi trebalo da radi. Usput posalji kod greske koju javi okruzenje pa cemo dalje da vidimo, ili ti sam otkucaj kod i pogledaj u helpu objasnjenje

Pozdrav
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC06.06.2005. u 23:00 - pre 198 meseci
ovo je ceo kod:
Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication4
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Data.SqlClient.SqlConnection sqlConnection1;
        private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
        private WindowsApplication4.DataSet1 dataSet11;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            sqlConnection1.Open();
            sqlDataAdapter1.Fill(dataSet11);
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
            this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
            this.dataSet11 = new WindowsApplication4.DataSet1();
            ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
            this.SuspendLayout();
            // 
            // sqlConnection1
            // 
            this.sqlConnection1.ConnectionString = "data source=BOOMMBAAA;initial catalog=Northwind;integrated security=SSPI;persist " +
                "security info=False;workstation id=BOOMMBAAA;packet size=4096";
            // 
            // sqlDataAdapter1
            // 
            this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
            this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                                                                                                      new System.Data.Common.DataTableMapping("Table", "Orders", new System.Data.Common.DataColumnMapping[] {
                                                                                                                                                                                                                new System.Data.Common.DataColumnMapping("OrderID", "OrderID"),
                                                                                                                                                                                                                new System.Data.Common.DataColumnMapping("OrderDate", "OrderDate"),
                                                                                                                                                                                                                new System.Data.Common.DataColumnMapping("ShipName", "ShipName")})});
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(120, 51);
            this.textBox1.Name = "textBox1";
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "";
            //this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(120, 97);
            this.textBox2.Name = "textBox2";
            this.textBox2.TabIndex = 1;
            this.textBox2.Text = "";
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(120, 143);
            this.textBox3.Name = "textBox3";
            this.textBox3.TabIndex = 2;
            this.textBox3.Text = "";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(16, 48);
            this.button1.Name = "button1";
            this.button1.TabIndex = 3;
            this.button1.Text = "Refresh";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(248, 48);
            this.label1.Name = "label1";
            this.label1.TabIndex = 4;
            this.label1.Text = "Order Id";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(248, 100);
            this.label2.Name = "label2";
            this.label2.TabIndex = 5;
            this.label2.Text = "Order Date";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(248, 152);
            this.label3.Name = "label3";
            this.label3.TabIndex = 6;
            this.label3.Text = "Ship Name";
            // 
            // sqlSelectCommand1
            // 
            this.sqlSelectCommand1.CommandText = "SELECT OrderID, OrderDate, ShipName FROM Orders";
            this.sqlSelectCommand1.Connection = this.sqlConnection1;
            // 
            // dataSet11
            // 
            this.dataSet11.DataSetName = "DataSet1";
            this.dataSet11.Locale = new System.Globalization.CultureInfo("sr-SP-Cyrl");
            this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(384, 283);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label3,
                                                                          this.label2,
                                                                          this.label1,
                                                                          this.button1,
                                                                          this.textBox3,
                                                                          this.textBox2,
                                                                          this.textBox1});
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }




         private void button1_Click(object sender, System.EventArgs e)
        {
            if (textBox1.Text != " ") //nije prazan text box
            {
                textBox2.Text =VratiIzBazeShipName(textBox1.Text);
                textBox3.Text =VratiIzBazeOrderDate(textBox1.Text);
            }
        }

             private string VratiIzBazeShipName(string ORderID)
            {

                SqlCommand dataCommand = new SqlCommand();
                dataCommand.CommandText =" SELECT ShipName FROM Orders WHERE OrderID='"+ORderID+"'";
                SqlDataReader dataReader = dataCommand.ExecuteReader();
                string ShipName = string.Empty  ;
                while(dataReader.Read())
                {
                    string ShipName1 = dataReader.GetString(8);
                    Console.Write(ShipName1);

                }
                
                dataReader.Close();
                 return(ShipName);

            }
    
            private string VratiIzBazeOrderDate(string ORderID)
            {
                SqlCommand dataCommand = new SqlCommand();
                dataCommand.CommandText =" SELECT OrderDate FROM Orders WHERE OrderID='"+ORderID+"'";
                SqlDataReader dataReader = dataCommand.ExecuteReader();
                string OrderDate = string.Empty  ;
                while(dataReader.Read())
                {
                    DateTime OrderDate1 = dataReader.GetDateTime(3);
                    Console.Write(OrderDate1);
                }
                dataReader.Close();
                 return(OrderDate);
            }

        }
    }

Jeste u pitanju je Northwind baza, tabela Orders.
Sada se program iskompajlira ali se zapuca kada se unese neki OrdersID i klikne Refresh.


Bogami ovo ce da potraje
 
Odgovor na temu

dc43
Dragoljub Ćurčić
programer, Chinook Software
Subotica, Serbia

Član broj: 19134
Poruke: 50
195.252.80.*

Sajt: bogiwoye.info


+2 Profil

icon Re: Mala pomoc oko C#, UPOMOOOC07.06.2005. u 00:23 - pre 198 meseci
Ne mora da potraje. Moras nauciti da citas kod. I da ga razumes.

Tacno su ti rekli ostali, ali nisi bas najbolje resio to.

string ShipName = string.Empty ;
while(dataReader.Read())
{
string ShipName1 = dataReader.GetString(8);
Console.Write(ShipName1);
}
return(ShipName);

Sta ne valja tu? Ti vracas prazan string. ShipName postavis da bude prazan, a ShipName1 sadrzi podatak. Taj deo koda bi verovatno bolje radio ovako:

string ShipName = string.Empty ;
while(dataReader.Read())
{
ShipName = dataReader.GetString(8);
Console.Write(ShipName);
}
return(ShipName);

Na ovaj nacin ShipName promenljiva vazi i unutar while bloka i van njega, jer je van njega i deklarisana. Sadrzace podatak.
...
Nisam siguran da li je ovo OK:

dataCommand.CommandText =" SELECT ShipName FROM Orders WHERE OrderID='"+ORderID+"'";

Ono sto mi izgleda cudno je koriscenje apostrofa oko OrderID parametra. Nije problem sto je on prosledjen proceduri kao string, ali obicno su u bazi ID polja brojevi, a ne stringovi. A u SQL upitu apostrofi ne okruzuju brojeve. Ipak, to je na tebi da utvrdis. Mozda je kod tebe string u bazi, a mozda i nije.

Ostatak koda nisam stigao pogledati, jer imam malo vremena sada.
 
Odgovor na temu

Shejn
Srbija

Član broj: 11830
Poruke: 232
*.nspoint.net.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC07.06.2005. u 17:12 - pre 198 meseci
[
Citat:
dc43: Ne mora da potraje. Moras nauciti da citas kod. I da ga razumes.

Tacno su ti rekli ostali, ali nisi bas najbolje resio to.

string ShipName = string.Empty ;
while(dataReader.Read())
{
string ShipName1 = dataReader.GetString(8);
Console.Write(ShipName1);
}
return(ShipName);

Sta ne valja tu? Ti vracas prazan string. ShipName postavis da bude prazan, a ShipName1 sadrzi podatak. Taj deo koda bi verovatno bolje radio ovako:

string ShipName = string.Empty ;
while(dataReader.Read())
{
ShipName = dataReader.GetString(8);
Console.Write(ShipName);
}
return(ShipName);

Na ovaj nacin ShipName promenljiva vazi i unutar while bloka i van njega, jer je van njega i deklarisana. Sadrzace podatak.
...
Nisam siguran da li je ovo OK:

dataCommand.CommandText =" SELECT ShipName FROM Orders WHERE OrderID='"+ORderID+"'";

Ono sto mi izgleda cudno je koriscenje apostrofa oko OrderID parametra. Nije problem sto je on prosledjen proceduri kao string, ali obicno su u bazi ID polja brojevi, a ne stringovi. A u SQL upitu apostrofi ne okruzuju brojeve. Ipak, to je na tebi da utvrdis. Mozda je kod tebe string u bazi, a mozda i nije.

Ostatak koda nisam stigao pogledati, jer imam malo vremena sada.


Bez ljutnje ali ako nemas vremena nemoj ni da se petljas oko "ja mislim da ..." odgovora!

Da si procitao odgovore na ovaj problem video bi da sam ja to pokusao sto mi ti savetujes i da sam okacio taj kod i gresku koju mi javlja ( pogledaj petu poruku pre tvoje) !

Ako nemas vremena nemoj da ti ja oduzimam i to malo sto imas.

POZDRAV!!
 
Odgovor na temu

Čarli
BG

Član broj: 38963
Poruke: 6
*.wireless.org.yu.



Profil

icon Re: Mala pomoc oko C#, UPOMOOOC08.06.2005. u 09:39 - pre 198 meseci
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication4
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private WindowsApplication4.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();


}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new WindowsApplication4.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "data source=BOOMMBAAA;initial catalog=Northwind;integrated security=SSPI;persist " +
"security info=False;workstation id=BOOMMBAAA;packet size=4096";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Orders", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("OrderID", "OrderID"),
new System.Data.Common.DataColumnMapping("OrderDate", "OrderDate"),
new System.Data.Common.DataColumnMapping("ShipName", "ShipName")})});
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(120, 51);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(120, 97);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(120, 143);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "Refresh";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(248, 48);
this.label1.Name = "label1";
this.label1.TabIndex = 4;
this.label1.Text = "Order Id";
//
// label2
//
this.label2.Location = new System.Drawing.Point(248, 100);
this.label2.Name = "label2";
this.label2.TabIndex = 5;
this.label2.Text = "Order Date";
//
// label3
//
this.label3.Location = new System.Drawing.Point(248, 152);
this.label3.Name = "label3";
this.label3.TabIndex = 6;
this.label3.Text = "Ship Name";
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT OrderID, OrderDate, ShipName FROM Orders";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("sr-SP-Cyrl");
this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(384, 283);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3,
this.label2,
this.label1,
this.button1,
this.textBox3,
this.textBox2,
this.textBox1});
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}




private void button1_Click(object sender, System.EventArgs e)
{
if (textBox1.Text != " ") //nije prazan text box
{
sqlConnection1.Open();
textBox2.Text =VratiIzBazeShipName(textBox1.Text);
textBox3.Text =VratiIzBazeOrderDate(textBox1.Text);
sqlConnection1.Close();
}
}

private string VratiIzBazeShipName(string ORderID)
{
int ordID1 = int.Parse ( ORderID );

SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText =" SELECT ShipName FROM Orders WHERE OrderID=ordID1 ";
SqlDataReader dataReader = dataCommand.ExecuteReader();
string strShipName = "" ;
while(dataReader.Read())
{
strShipName = dataReader.GetString(8);
Console.Write(strShipName);

}

dataReader.Close();
return(strShipName);

}

private string VratiIzBazeOrderDate(string ORderID)
{
int ordID2 = int.Parse ( ORderID );
SqlCommand dataCommand = new SqlCommand();
dataCommand.CommandText =" SELECT OrderDate FROM Orders WHERE OrderID=ordID2 ";
SqlDataReader dataReader = dataCommand.ExecuteReader();
string strOrderDate = "" ;
while(dataReader.Read())
{
strOrderDate = dataReader.GetDateTime(3).ToString();
Console.Write(strOrderDate);
}
dataReader.Close();
return(strOrderDate);
}

}
}

.........................................................................

Evo, ispravio sam ti kod, no, ako ti ponovno ne proradi, javi se pa da vidim da ti to isprogramiram od početka.

Ispravke ---
1. Konekciju sam otvorio u klik proceduri Refreš dugmeta i tu je i zatvorio --- nije u redu da je otvaraš odmah na početku aplikacije ... potrebno je da je otvaraš kada ti treba, te potom zatvoriš ;
2. Promenio sam ti deklaracije u metodama za isšitavanje, jer si imao dvostruke deklaracije, a u smislu datuma porudžbine i pogrešne tipove ( najpre tip string, a potom u petlji tip 'DataTime' strukture ),
3. Usput, imaš viška data adapter i data set koje niti ne koristiš --- ti koristiš ekstenzivan način pristupa Sql bazi uz upotrebu samo objekata tipa 'SqlCommand' i 'SqlConnection' --- dakle direktan pristup. No, ponekad od viška glava ne boli, sem što će ti kompajler ( ako nije drugačije podešen ) javiti 'warning' u smislu da si deklarisao varijable koje nikada ne koristiš.
4. Višak su ti i naredbe za ispis na konzolu, pošto ispisuješ na Windows formu !


 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: Mala pomoc oko C#, UPOMOOOC

[ Pregleda: 3086 | Odgovora: 14 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.