Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i have this syntax
C#
lcuser = this.txtUserName.Value;
       lcpassword = this.txtPassword.Value;
       SqlConnection con = new SqlConnection("Data source = UIS-PC\\SQLEXPRESS; Initial Catalog=Database1; integrated security = SSPI;");
       SqlCommand selectid = new SqlCommand("SELECT cuser, cpassword, cbranch, caddress FROM branch", con);
       con.Open();
       SqlDataReader BranchReader = selectid.ExecuteReader();
       int branch = BranchReader.GetOrdinal("caddress");
       while (BranchReader.Read())
       {

           gcbranch = BranchReader.GetName(2).ToString();
           gcaddress = BranchReader[2].ToString();
           gcuser = BranchReader.GetValue(3).ToString();
           gcpassword = BranchReader.GetValue(2).ToString();


GetValue(2) shows null although i have it filled in the table database
GetValue(2) some times shows empty although they have data

thanks in advance
Posted
Updated 3-Nov-11 8:18am
v2

try
C#
gcbranch = BranchReader[2].ToString();
gcaddress = BranchReader[3].ToString();
gcuser = BranchReader[0].ToString();
gcpassword = BranchReader[1].ToString();
 
Share this answer
 
Comments
ahmad zrein 3-Nov-11 23:59pm    
I tried i before it give the same result null
When you use BranchReader.Read() in a While rotation it will return a bool value and it will called by your application one time so when it comes to end it can return null.Try to use a for rotation and int temp value.Remember to increase your temp's value on every rotation with temp++.And remember to use your BranchReader.Read() method on every for rotation's begining;
This is one of these query mistakes.Try and return to me.
 
Share this answer
 
Comments
ahmad zrein 4-Nov-11 7:18am    
protected void ButtonLogOn_Click(object sender, EventArgs e)
{
string lcuser, lcpassword;
string gcuser, gcpassword, gcbranch, gcaddress;
lpass = false;
lcuser = this.txtUserName.Value;
lcpassword = this.txtPassword.Value;
SqlConnection con = new SqlConnection("Data source = UIS-PC\\SQLEXPRESS; Initial Catalog=Database1; integrated security = SSPI;");
SqlCommand selectid = new SqlCommand("SELECT cuser, cpassword, cbranch, caddress FROM branch", con);
con.Open();
SqlDataReader BranchReader = selectid.ExecuteReader();
for (int i = 0; i < BranchReader.FieldCount; i++)
{
BranchReader.Read();
gcuser = BranchReader.GetValue(0).ToString();
gcpassword = BranchReader.GetValue(1).ToString();
gcbranch = BranchReader.GetValue(2).ToString();
gcaddress = BranchReader.GetValue(3).ToString();
string message = gcuser + gcpassword + gcbranch + gcaddress;
string caption = "Where am i";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show(message, caption, buttons);


//if (gcuser.Trim() == lcuser.Trim() )
//& lcpassword.Trim() == gcpassword.Trim())
// {
lpass = true;
//MyVariables.Varaibles.gcbranch = gcbranch;
//MyVariables.Varaibles.gcaddress = gcaddress;

//string message = gcuser + gcpassword + gcbranch + gcaddress;
//string caption = "Where am i";
//MessageBoxButtons buttons = MessageBoxButtons.YesNo;
//DialogResult result;

// Displays the MessageBox.

//result = MessageBox.Show(message, caption, buttons);

//Response.Redirect("default.aspx");
// }
BranchReader.NextResult();
}

BranchReader.Close();
con.Close();

this the whole code
it display only getvalue(0) and getvalue(1)correct but getvalue(2) and getvalue (3) is empty although there is data in the table for all fields,
i insert them by hand

thanks for the help
SercanOzdemir 4-Nov-11 8:50am    
Sometimes database and interface connection throws and exception about column name's length.I think it can be connected with your problem.Try to use 3 chars column names.Like Weather-> Wth
ahmad zrein 4-Nov-11 14:30pm    
thanks i solve it it is my mistake the code are correct and work fine
sorry for interuption

thanks
SercanOzdemir 4-Nov-11 17:31pm    
Your Welcome my pleasure :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900