none
I need help sending LoginName to my database. I need help asap my work is due in tonight!! RRS feed

  • Question

  • I am having trouble sending my LoginName to the database and I need a way of doing it through sqldatasource because all my work is done in that way and that is the way I am meant to do for this coursework. I dont have a session or anything all I have at the moment is LoginName and I cant send it. PLEASE HELP!!
    Thursday, December 24, 2015 6:17 PM

All replies

  • Hi Halil,

    Since your issue is more related to .Net development. I moved this case to the Data Platform Development forum.

    Thanks for your understanding.

    Best Regards,

    Lake Xiao                                    

    Friday, December 25, 2015 3:18 AM
  • Hello Halil_B,

    According to your description, you want to connection a database. Could you tell me what kind of database you are using .

    If it’s sql server, the following is a ado.net demo about connecting database for your reference.

    string connectionString = ”Server=yoursqlserverIpaddress;Database=yourdatabase;Uid=yoursqlserveruserId;Pwd=yoursqlserverPassword;”;
    string sqlString = “insert into xxx (aa,bb,cc) values (‘aa’,’bb’,’cc’)”;
    // ExecuteNonQuery insert update delete
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
         using (SqlCommand cmd = new SqlCommand(sqlString, connection))
         {
               try
               {
                   connection.Open();
                   int rows = cmd.ExecuteNonQuery();
               }
               catch (System.Data.SqlClient.SqlException E)
               {
                    connection.Close();
                    throw new Exception(E.Message);
               }
         }
    }

    //select

    string sqlString = “select * from aa”;
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        DataSet ds = new DataSet();
        try
         {
              connection.Open();
              SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
              command.Fill(ds, "ds");
          }
          catch (System.Data.SqlClient.SqlException ex)
          {
                        throw new Exception(ex.Message);
          }
    }

    Best regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Friday, December 25, 2015 5:23 AM
    Moderator
  • You probably missed your deadline already, since you posted this initially almost a day ago.

    I was going to ask what code you were currently using ... it's easier to help someone when we have a bit of code that we can see what you might be doing wrong. I suspect that you simply did not have the correct connection string. There's a pretty easy way to determine the connection string to use in your code. Please see my blog post where I describe how to do this:

    http://geek-goddess-bonnie.blogspot.com/2015/02/easy-peasy-connection-strings.html


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, December 25, 2015 3:20 PM